Wordpress - if (is_page(**PAGE ID**)) not working
you can use this for
<?php
global $post;
if( $post->ID == 346) { ?>
<!-- do your stuff here -->
<?php } ?>
you can use this anywhere either in header or anywhere else.
A simpler solution will be to pass the title
or the slug
as argument in is_page()
. You won't have issues if you duplicate that page on another server.
<?php
if (is_page( 'Page Title' ) ):
# Do your stuff
endif;
?>
Hooks such as init
will not work at all.
You have to hook at least on parse_query
.
Everything bellow will work:
is_page(198); # ID (int)
is_page('198'); # ID (string)
is_page('Some Title'); # Title, case-sensitive
is_page('some-title'); # Slug
But it must be hooked at least in parse_query
or any other hook after it. You can see WordPress hook order here: https://codex.wordpress.org/Plugin_API/Action_Reference