DigitCodes

Coding Notes


Follow @afsalrahim
  • PHP Codes
  • Web Design
    • CSS Tricks
  • WordPress
    • WordPress Tips
    • WordPress Themes
    • WordPress Plugins
  • Blogging
You are here: Home / Wordpress / Wordpress Codes / How to Show Custom Sidebar for Specific Pages in Wordpress using Genesis framework

How to Show Custom Sidebar for Specific Pages in WordPress using Genesis framework

March 11, 2013 by Afsal Rahim 2 Comments

Custom Sideabr for specific pages in wordpress

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.

[adslot]

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.

Code Explanation:

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.

Must Read: How to Easily Show Adsense Ads anywhere Inside the Blog Post ?

By the way there are also a lot of wordpress plugins which can do the same effect for you.

Filed Under: Wordpress Codes Tagged With: Genesis theme

Comments

  1. vino says

    May 30, 2014 at 1:42 pm

    Well explained. Does this work only for genesis themes?

    Reply
  2. surendra says

    June 29, 2015 at 9:30 pm

    wow thanks for this tutorial, it is prove helpful to me.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Sponsered

FREE Email Updates

Subscribe to our newsletter to get all the latest updates to your inbox..!



TRENDING

Add a Stylish Email Subscription Form for your Blog

How to Easily Show Adsense Ads anywhere Inside the Blog Post

The Easy Way to Show Placeholder images or Dummy images

Disable WordPress Autosave and Revisions

Return to top of page

Copyright © 2016 · digitcodes.com · Privacy Policy · Contact Us