In this post I will tell you how you can show a custom sidebar instead of your usual sidebar for a specific page in your WordPress website which is using the Genesis framework.
I got this recent fiverr gig in which the client need to show up a specific sidebar for one of his page. He had created a page named Contact (having the slug or permalink: contact) and now instead of showing up the general sidebar widgets which are shown in all other pages, he needs to have a specific sidebar widget shown there.
So in order to accomplish this we have to edit the functions.php theme file. Here is the code which I came up with.
Now let me break it down for you, First we register the new sidebar using the genesis_register_sidebar() and this creates a new sidebar section named Contact Page Sidebar where you can add widgets.
In the child_sidebar_for_page() we are checking for the page using the if ( is_page(‘contact’) ) it needs to be noted that you have to provide the exact slug name or permalink (in our case its contact).
Further remove_action( ‘genesis_after_content’, ‘genesis_get_sidebar’ ); removes the general sidebars and then we use add our custom sidebar using the code add_action( ‘genesis_after_content’, ‘get_sidebar_for_page’ );
The function get_sidebar_for_page() simply retrieves the sidebar using dynamic_sidebar( ‘contact-sidebar’ );
and displays it.
By the way there are also a lot of wordpress plugins which can do the same effect for you.