Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Josh Miclette
PLUS
Josh Miclette
Courses Plus Student 6,227 Points

Is it possible to add a select menu to choose a sidebar in the page attributes section in WordPress?

Hi Treehouse community, I have a question regarding WordPress. After taking Bootstrap to WordPress by Zac Gordon (which I highly recommend), I continued to build my theme. I've read through the Codex, but I cannot find how to add a sidebar selection to the page attributes box. I've seen this before on other templates, and I'm sure there is a plugin for it, but I'd like to code this myself. Any references or help will be greatly appreciated.

Thanks! Josh

3 Answers

Yes you can choose which page using this plugin:

https://wordpress.org/plugins/display-widgets/ .

I used it recently for a project.

Josh Miclette
Josh Miclette
Courses Plus Student 6,227 Points

Thanks Luke, this solution works great on my current project, but I'd eventually like to code it. Are you aware of any references or tutorials?

Thanks, Josh

There are several different approaches. You can create a custom sidebar widget section for each page you need different widgets on, but this still doesn't allow you to use the backend in the same way as that plugin does. Try reverse engineering their code in the plugin, as long as they didn't obfuscate it then you might be able to figure out what they did to add the checkboxes for those sections.

The WordPress codex also seems to recommend that plugin in addition to another one. I'm sure there is someone out there who was written the code to do it but I have yet to find anything.

Stanley Thijssen
Stanley Thijssen
22,831 Points

Cant you just create template file with the sidebar you prefer inside of it?

Josh Miclette
Josh Miclette
Courses Plus Student 6,227 Points

Thanks Stanley for your response.

Here's what I did, and it currently works. I created a new template which I am able to choose from the Templates drop-down. I associated that template with a new sidebar.

My question is instead of creating all of these custom templates (which is more work in the end), I'd like to just create a custom sidebar, and have the option to select it within the page attributes. Basically I want to use page.php for all my common pages but have the option to choose a different sidebar.

Stanley Thijssen
Stanley Thijssen
22,831 Points

Best option for you now is using a plugin or use the custom template's. I advice you to follow the plugin development course on Wordpress here on treehouse to learn more about making such functionalities yourself.