The WordPress sidebar is such an important piece of real estate on your blog, a lot of internal navigation clicks happen there and lots of people can exit through the links you display there too.
So why does such an important part of your blog get ignored, or at least treated in exactly the same way on every single page, be it the homepage or a single post? Developing an idea from Joost’s WordPress SEO guide, I’m going to look at how you can customise the links or features you display relative to the page your visitor happens to be, er, visiting.
I’ve spent a few hours setting up the basics on my blog and I’m pretty sure I’m going to be thinking about and refining my sidebar strategy on an ongoing basis until it’s right. Here’s the screenshot of my homepage, with each important section highlighted:
Compare that to the sidebar you see to your right. I’ve taken Joost’s advice and rethought my sidebar. How do you set up your sidebar so it conditionally displays features relevant to content type? The WordPress conditional tag will be the lesson for the day.
Using the conditional tag to display features when a visitor hits your homepage (but not the rest of the site) is reasonaly simple. A conditional tag checks to see if something is true or false, so if you ask “is this the homepage?” you’ll either recieve a true or false response. The conditional tag we’re going to use looks like this:
and finish with:
You’re going to need to be comfortable making a small edit to your sidebar.php file by clicking to Design>Theme editor>Sidebar (sidebar.php). I’m going to use my “Find me on” section as the example.
By carefully surrounding the code with our conditional tags you can easily “hide” sections of irrelevant content. Joost’s post covered removing your blogroll links in the same way. This was a little harder and in the end, I used a
tag to encapsulate the php which looks at the WordPress database for your links. Here’s how it looks:
There’s more to conditional tagging than the is_home argument – there’s some really interesting ones in the WordPress codex such as:
is_single() – When any single Post page is being displayed.
is_single('17') – When Post 17 is being displayed as a single Post
is_page() – When any Page is being displayed
is_page('about-me') – When the Page with a post_name (slug) of “about-me” is being displayed
There are heaps more so I strongly recommend you take a look on the WordPress codex site. I also strongly recommend that you back up the contents of your sidebar.php file!
Want to see the results? Two weeks later I wrote up the results in a post titled: reduce the bounce rate on your blog