Support » Fixing WordPress » IF ELSE code for body ID check

  • natpoit7

    (@natpoit7)


    Hi,

    I need to use different ID style for the body on some pages, and one different ID for all other pages. I have a code

    <?php if (is_front_page()) {
    ?>
    <body>
    
    <?php
    }
    elseif (is_page( 'page1'||'page2'||'page3'||'page4' ) ) {
    ?>
    <body id="<?php echo get_query_var('name'); ?>">
    
    <?php } else { ?>
    <body id="defaultid">
    
    <?php } ?>

    It works for page1, page2, page3, page4: I
    <body id=”page1″>, <body id=”page2″>, <body id=”page3″>, <body id=”page4″>
    It works for the main page, I have <body>

    but for all other pages I don’t have <body id=”defaultid”>, i.e. if my page is ‘somepage’ I want <body id=”defaultid”>, but my code returns me
    <body id=”somepage”>

    What is wrong with my if/else?

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • This is just a thought, but I was reading the Codex page for is_page, and I noticed the examples use arrays for multiple is_page evaluations. Might be worth a try.

    So instead of:

    elseif (is_page( 'page1'||'page2'||'page3'||'page4' ) ) {

    you would have

    elseif (is_page( array ( 'page1', 'page2', 'page3', 'page4') ) ) {

    natpoit7

    (@natpoit7)

    thank you very much, it does work

    Regards,
    Nathalie

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘IF ELSE code for body ID check’ is closed to new replies.