Ryan Ryan - 1 year ago 72
PHP Question

WordPress sidebar: appear only on certain pages

How can I edit the php to get my WordPress sidebar to only appear on select pages (i.e. not on the home and about pages)?

I'd prefer php over css if possible.

Answer Source

You can use the function is_page() in your template and rendering the sidebar only if you need to.

Small example, in sidebar.php of the twentyten theme of WordPress

<div id="secondary" class="widget-area" role="complementary">
        <ul class="xoxo">
             if (is_page('my-page')) { 
                  dynamic_sidebar( 'secondary-widget-area' ); }
</div><!-- #secondary .widget-area -->

This little snippet outputs the sidebar only if you are in the page that has the slug 'my-page'.
Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download