Archived topic
Add widget after content?
6 replies · Started by Edin on December 18, 2017
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
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
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.
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 :)
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!
Ah, got it, removed it in the customizer.
Awesome - glad I could help! :)