This one is for hiding or displaying a WordPress widgetized area on a template page. An initial search on this turned up a whole lot of widget logic plugins and that is NOT what this is about. This is for when you insert a widget area into a WordPress template page using PHP. It’s easy to insert the code if you KNOW that you need it in a particular place. I’ve been doing that for the last couple of years, but now I wanted to only display the widget area if I actually dropped a widget in there TO display.
I have a customer that needs a whole lot of information displayed on the home page. The stock template from which I started (SimplePress by Elegant Themes) does a nice job at hiding the complexities from the average user. In this case, I knew needed a lot more widget areas and no way of knowing exactly which ones the customer was going to end up wanting when we took the site to production. So I added a ton of widget areas into the page templates. I hate having to run through the logic and code more than once in a project if I can avoid it.
Unless you fill in all those widget areas, you end up with a lot of funky little blank areas where you’ve placed the holding divs – see yesterday’s code for adding widget areas to a WordPress template page. I guess this is more the proper way to do it… So how to get rid of those blank div areas until you’re ready to use them? Modify the insertion routine just a bit.
This PHP code snippet allows me to drop this code in and leave it tucked away until needed. Then display it when there’s something there, but until the customer comes to me and says, “Hey can you add some content on the front page? We need a new area to show…” Yes, of course I can.
It’s going to sit there quietly waiting for my beck and call.