Reputation: 49
I'm trying to use the is_page function in wordpress and it's not working.
I read here that <?php wp_reset_query(); ?>
should solve the problem, but it didn't help. Here is the code:
<?php wp_reset_query(); ?>
<?php if (is_page(379) ): ?>
<!-- Google Analytics Content Experiment code -->
<?php endif; ?>
Any idea/suggestions on this?
Thanks!
Upvotes: 0
Views: 12289
Reputation: 325
None of the other solutions worked for me. What did work was to use the wp
hook.
add_action('wp', 'page_check');
function page_check() {
if (is_page('my-page-slug')) {
// code to run on this page
}
}
Upvotes: 7
Reputation: 1960
I had a similar problem recently and it's because I was using query_posts somewhere on the page.
The way I tested it was to echo the $post->ID at the very top of the template file and it gave me the correct ID.
when I echoed it at the bottom (after my query_posts), it was not getting the correct ID.
So you might want to test by doing this and changing any query_posts you have to use WP_Query instead: http://codex.wordpress.org/Class_Reference/WP_Query
Upvotes: 0
Reputation: 46
this works fine for me
<?php if(is_page(379)): ?>
<?php echo 'x'; ?>
<?php endif; ?>
Upvotes: 0
Reputation: 1054
Try this
<?php if (get_the_ID()==379): ?>
<!-- Google Analytics Content Experiment code -->
<?php endif; ?>
Upvotes: 0