Define a specific sidebar using custom fields

WP-PageNavi Review - numerical pagination

Many of you know WordPress will let you create custom sidebar templates using the same file naming method as other templates eg: sidebar-{name}.php. Replacing the get_sidebar() function with this snippet will let you define a custom sidebar for specific posts using custom fields. For more details on sidebar templates via this document, http://codex.wordpress.org/Function_Reference/get_sidebar

          $sidebar = get_post_meta($post->ID, "sidebar", true);

Comments  Leave a Reply

  1. thnks for the code

  2. teste

  3.  Hmm… not quite sure when I would use this one…

    1. I can see a few reasons to use this snippet if you have a site and you need to replace the sidebar on all but a few pages. Another could be displaying specific information for pages etc. It is a nice little snippet to keep in your hat on the off chance you need it. 🙂

      1. I read this… http://codex.wordpress.org/Function_Reference/get_sidebar
        Your post makes MUCH more sense to me now 🙂 

        1.  Ahh ok cool, I linked the document in the post so if others have questions they can view the wordpress codex.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!