Do you want to define the custom sidebar for specific posts by replacing the get_sidebar()
function? While there can be no plugin to achieve this, we have created a quick code snippet that you can use to define a specific sidebar using custom field in WordPress.
Instructions:
All you have to do is add this code to your theme’s template file where you want to call the custom sidebar:
<?php $sidebar = get_post_meta($post->ID, "sidebar", true); get_sidebar($sidebar); ?>
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 62 best free WordPress blog themes and how to set up download tracking in WordPress with Google Analytics.
thnks for the code
teste
Hmm… not quite sure when I would use this one…
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. 🙂
I read this… http://codex.wordpress.org/Function_Reference/get_sidebar
Your post makes MUCH more sense to me now 🙂
Ahh ok cool, I linked the document in the post so if others have questions they can view the wordpress codex.