Support » Fixing WordPress » Make sidebar change depending on page id

  • mundi89

    (@mundi89)


    I would like to have different sidebars depending on the page a user is on. Can anyone explain how to do this? I assume it would require some sort of “if statement”, but I am unsure of the syntax.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • rob1n

    (@rob1n)

    You can use the conditional tag is_page().

    It takes one argument, which can be the page ID or name.

    Ex:

    if (is_page(2)) // page id == 2

    -or-

    if (is_page(‘About’)) // About page

    Thread Starter mundi89

    (@mundi89)

    Okay, so if I want an image to appear in the sidebar on page 9, what is the syntax in sidebar.php

    <?php if( is_page(9) ) ?>
    Code for Image
    ….

    rob1n

    (@rob1n)

    <?php if (is_page(9)) : ?>
    your code/html or whatever here
    <?php endif; ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Make sidebar change depending on page id’ is closed to new replies.