WordPress is_page() for blog post listing page

I’m trying to use an is_page() conditional in WordPress to detect whether or not the current page is the blog listing page (or a blog post page actually). The conditional works fine for any other page (contact, whats-on etc) but for some reason it doesn’t work for the blog page.

Plus the actual blog post pages – URLs are www.domain.com/the-post-title format, so I can’t check for ‘blog’ in the URL from $_SERVER or anything. Any help would be hugely appreciated.

Related posts

Leave a Reply

3 comments

  1. We need to check:

    • if this page is blog page.
    • if this page is “page for posts”

      function is_page_for_posts() {
          $result = false;
      
          if ( is_home() && ! is_front_page() ) {
              $page = get_queried_object();
      
              $result = ! is_null( $page ) && $page->ID == get_option( 'page_for_posts' );
          }
      
          return $result;
      }
      
  2. According to this article, this is how you use these kind of conditional functions:

    if ( is_front_page() && is_home() ){
        // Default homepage
    } elseif ( is_front_page()){
        //Static homepage
    } elseif ( is_home()){
        //Blog page
    } else {
        //everything else
    }