if (is_page(**PAGE ID**)) not working

  • I'm following this tutorial on adding Google Content Experiments code to header.php.

    I added the following code to header.php:

    <?php if (is_page('346') ):?>
        <!-- Google Analytics Content Experiment code -->
            ...
        <!-- End of Google Analytics Content Experiment code -->
    <?php endif; ?>
    

    This didn't produce the content experiment code on the front end. I tried:

    <?php if (is_page(346) ):?>
        <!-- Google Analytics Content Experiment code -->
            ...
        <!-- End of Google Analytics Content Experiment code -->
    <?php endif; ?>
    

    This didn't work either.

    Can you see why this code is not working? Thanks.

    You did double-check that your are on the page with ID 346, right?

    If this is another contenttype, try using `if ( get_the_ID() == 346 )`.

    Yes kraftner. I changed tact and started using WP Content Experiments & Event Tracking, which works for me.

  • you can use this for

    global $post;
    
    <?php if( $post->ID == 346) { ?>
    
          <!-- do your stuff here -->
    
    <?php } ?>
    

    you can use this anywhere either in header or anywhere else.

    What if I want to add a PHP function in ? Do I just use `ID == 346) { } ?>`

    Yes you can call your function in

    Hmm. Not working for me. I suppose I'll make a post.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM