• I’m been attempting to get the following chunk of code to work but it does not seem to. If I remove the “25” parameter from the is_page function, it works fine, but as soon as I enter any type of paramter (page ID, page-slug or page title) for any page, it simply falls through to the else option. Can someone advise me on what I’m doing wrong here? Thanks!

    <h4><?php if (is_page('25')) { _e('Tracks:'); } else { _e('Links:'); } ?></h4>
    <ul class="mnav">
    <?php if (is_page('25')) { wp_get_links('3'); } else { wp_get_links('1'); } ?>
    </ul>

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try is_page(25) maybe? — i.e. send the parameter as an integer, not a string.

    Thread Starter Kenn

    (@kenn)

    Nope…I tried it both with and without quotes on the ID number, as well as using page-slug and the page title (all of which are supposed to be acceptable parameters for this function.

    “as well as using page-slug and the page title (all of which are supposed to be acceptable parameters for this function”

    I may be wrong but I don’t think so. Only the page ID is a valid parameter. As for it not working – I thought you had to be in “the loop” for the code to work. Is that where you’re executing it?

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    You’re wrong. ID, title, and slug are all acceptable inputs. See the is_page() function in functions.php, or just look at the codex: http://codex.wordpress.org/Conditional_Tags

    “You’re wrong. ID, title, and slug are all acceptable inputs.”

    Yes, you’re right – I was wrong. Having checked the code I can see that “post_title” and “post_name” will also work.

    Thanks for the correction. It looks like you have to be in “the loop” for it to work though.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Problem with is_page’ is closed to new replies.