skip to Main Content

Im trying to simply just output some HTML onto these 3 specific page-ids that I am referring too in the code below. Does anyone have any ideas as to why this php isn’t working? (its at the bottom of my functions.php file in the child theme.

 if( is_page('96') || is_page('98') || is_page('61') ) { ?> 
    <div class="test"><h2>test content</h2></div>
 <?php }

Any help would be appreciated as to why this ‘test content’ is not appearing on these pages.
Thanks!

2

Answers


  1. You can use
    get_the_ID(); or $post->ID;. you will get the ID of the current post of the loop

    like this

    $ids = [96, 78];
    if(in_array(get_the_ID(), $ids)) echo '<div class="test"><h2>test content</h2></div>';
    

    Please take a look at the docs :

    Login or Signup to reply.
  2. Try the below code that will work properly.

    if( is_page(96) || is_page(98) || is_page(61) ) : ?> 
        <div class="test"><h2>test content</h2></div>
     <?php endif;
    

    ===================== or ==========================

    $id = get_the_ID();
    if( ($id == 96) || ($id == 98) || ($id == 61) ) : ?> 
            <div class="test"><h2>test content</h2></div>
         <?php endif;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search