Cool use for secondary sidebar widget

I’m really liking some of the features in WordPress 3. As someone who writes WordPress templates for clients to use as a CMS, this version has gone a long way to make it even easier.

Because most of my WordPress installs are for commercial sites I tend to set them up with focus on writing pages rather than posts. Posts become great as “Latest News” style pages.

One of the things that makes this even easier is secondary widgets in the sidebar. Essentially this allows us to use the primary widget area to place additional content across the whole site and focuses the secondary widget area to focus on posts.

What this means is you can have your search bar or custom text that appears on every page but target blog specific items, such as calendars, tag clouds and archive links to posts only.

This is done by slightly modifying the secondary widget code in the sidebar.php file

As I want the secondary widget area to only display in posts I’m going to use the is_page conditional tag to do this. You should find the following code around line 45 on the sidebar.php page

 // A second sidebar for widgets, just because.
 if ( is_active_sidebar( 'secondary-widget-area' ) ) : ?>

Modify the above code so it looks like this

 // A second sidebar for widgets, just because.
 if ( !is_page() && ( is_active_sidebar( 'secondary-widget-area' ) ) ) : ?>

Secondary widgets will now display ONLY on the posts page – Simple, huh!

This entry was posted in Hints and Tips, Technical and tagged . Bookmark the permalink.

One Response to Cool use for secondary sidebar widget

  1. admin says:

    Another use for this is to enable the second sidebar just for a specific page (or a group of pages). The WP e-commerce plugin is a great example of this. By altering the code to suit you can add the widgets from that plugin to only work in the shopping cart pages.

    if ( is_page('products-page') && (is_active_sidebar( 'secondary-widget-area' ) ) ):

    Because all the products fall under the product-page slug, these widgets will appear on all pages. If you only wanted it to appear on one page you would use the page name ‘Product Page’ or the page ID

    Source :