[Resolved] Add widget after content?

Home Forums Support [Resolved] Add widget after content?

Home Forums Support Add widget after content?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #452232
    Edin

    I had something in my functions.php of my old theme “Divi”, that added a widget named “Single Post Sidebar” after the main content.

    function wpc_et_widgets_init() {
        register_sidebar( array(
            'name' => esc_html__( 'Single Post Sidebar', 'Divi' ),
            'id' => 'sidebar-6',
            'before_widget' => '<div id="%1$s" class="wpc-widget et_pb_widget %2$s">',
            'after_widget' => '</div> <!-- end .et_pb_widget -->',
            'before_title' => '<h4 class="widgettitle">',
            'after_title' => '</h4>',
        ) );
    }
    add_action( 'widgets_init', 'wpc_et_widgets_init' );

    How can I do that in GeneratePress?

    Thanks,
    Edin

    #452308
    Tom
    Lead Developer
    Lead Developer

    That code simply registers the widget area – it won’t display it.

    You would need to use this function to display the widget area on the frontend of the site: https://codex.wordpress.org/Function_Reference/dynamic_sidebar

    #452343
    Edin

    Got it, thanks!

    Where do I put the php-snipped to display the content? Can I put it in the “GP Hooks” somewhere, or do I have to put a single.php in my child-theme folder and put the snippet somewhere in there?

    I want to display it right after every single post.

    #452597
    Tom
    Lead Developer
    Lead Developer

    GP Hooks would be the preferable place to put it.

    You could do this:

    <?php if ( is_single() ) : ?>
        Your widgets in here
    <?php endif; ?>

    Make sure to check “Execute PHP” as well ๐Ÿ™‚

    #452748
    Edin

    Thank you, that worked great.

    How do I get rid of the category and the links to the previous/next articles output that’s been generated below each article?

    Thanks again!

    #452758
    Edin

    Ah, got it, removed it in the customizer.

    #453148
    Tom
    Lead Developer
    Lead Developer

    Awesome – glad I could help! ๐Ÿ™‚

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.