Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

WordPress how to add widget area after post ?

/**
 * After this line code is added by JU, can be removed
 */

function db_after_content_widget() {

	register_sidebar( array(
		'name'          => 'After Content Widget',
		'id'            => 'after_content_widget',
		'before_widget' => '<div>',
		'after_widget'  => '</div>',
	) );

}
add_action( 'widgets_init', 'db_after_content_widget' );

add_action('generate_after_main_content', function(){
	if ( is_active_sidebar( 'after_content_widget' ) && is_single() ) : ?>
		<div id="after-content-sidebar" class="widget-area" role="complementary">
			<?php dynamic_sidebar( 'after_content_widget' ); ?>
		</div>
	<?php endif;
});

Leave a Comment