• Resolved Anonymous User

    (@anonymized-21014217)


    I’m trying to check if the page exists, if it’s published, and display a link if it does. Here’s my code:

      <?php
        $page = get_page_by_title('Privacy Policy');
    
        if ( get_post_status($page) === 'publish' ):
      ?>
      <li>
        <a href="<?php echo get_page_link( get_page_by_title('Privacy Policy') ); ?>">Privacy Policy</a>
      </li>
      <?php
        endif;
    
        $page = get_page_by_title('Terms of Use');
    
        if ( get_post_status($page) === 'publish' ):
      ?>
      <li>
        <a href="<?php echo get_page_link( get_page_by_title('Terms of Use') ); ?>">Terms of Use</a>
      </li>
      <?php
        endif;
    
        $page = get_page_by_title('Terms of Use');
    
        if ( get_post_status($page) === 'publish' ):
      ?>
      <li>
        <a href="<?php echo get_page_link( get_page_by_title('Sitemap') ); ?>">Sitemap</a>
      </li>
      <?php endif; ?>

    It displays the list items for pages that don’t exist with a link to the sample post. Why is it doing that?

    • This topic was modified 3 years ago by Anonymous User.
Viewing 1 replies (of 1 total)
  • Thread Starter Anonymous User

    (@anonymized-21014217)

    Thanks! I found out I can create a footer menu on the theme’s 'footer.php' so I decided to go that route instead. It seems more complicated but it’s more semantic that way.

Viewing 1 replies (of 1 total)

The topic ‘Why Does get_page_by_title Return The Sample Post?’ is closed to new replies.