Archived topic
Displaying a dynamic sidebar
3 replies · Started by Jonathan on August 18, 2019
I've registered a new sidebar for an about section using the default wordpress code
add_action( 'widgets_init', 'my_register_sidebars' );
function my_register_sidebars() {
/* Register the 'primary' sidebar. */
register_sidebar(
array(
'id' => 'about',
'name' => __( 'About Sidebar' ),
'description' => __( 'About section sidebar' ),
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>'
)
);
/* Repeat register_sidebar() code for additional sidebars. */
}
I showed the sidebar via a hook element and using the layout to display on the selected pages using the following content:
<?php dynamic_sidebar( 'right-sidebar' ); ?>
It works however I now have the default sidebar showing as well which I don't need.
How can I unregister the default sidebar and show only the about one? Is this the best way to do this or should I do it another way i.e via a template?
I don't want to use a plugin for the sidebars.
thanks
Jon
Hi there,
Have you considered using a plugin like this?: https://wordpress.org/plugins/content-aware-sidebars/
It might simplify things.
Let me know :)
I have but I prefer to write the code and not use the plugins.
Then you might need to inspect the plugin code and see if you can write something similar.
Providing custom solution like this when there is plugin already available is out of the scope of this forum unfortunately.
The plugin should have minimal impact on your site.