I'd like a way to target only blog-area pages for specific formatting.

So far,

<?php if (is_home() || is_single() || is_category() || is_archive() ) { ?>

works okay, but is there a way to combine all of those into one single function to shorten it up a bit? so maybe in the functions it would set is_blog() to equal those four (or however many I want).

Seems a bit simple and probably is.... I just dont know what to search for to find information on this. Thanks!!

  • Hi there ... is_archive should cover is_category ... what type of formating are you trying to do? as its probably better to do this inside The Loop
    – Damien
    Commented Oct 12, 2012 at 21:27
  • How can we use is_blog() function in php?
    – user144186
    Commented May 24, 2018 at 6:27

3 Answers 3


Based on what you described:

function is_blog()
    return ( is_home() || is_single() || is_category() || is_archive() );

And then just call the is_blog() function whenever needed.

I also found this, which looks like a more specific way to do the same thing https://gist.github.com/1189639


All the is_*() »Conditional Tags« are wrappers for their is_* pendants in the global $wp_query object. They all reflect parts of the »Template Hierarchy« which determines which file should be loaded (if present) to display the request.

To make it short here're the most general:

  • is_archive() covers all Tag, Taxonomy, Category, Post Type (Post/Page/Attachments/links/Custom Post Type, etc.) archive pages (there's also is_post_type_archive() to lock those out).
  • is_home() and is_front_page() are basically the same, with the difference, that they distinguish the display setting for the front page: Latest posts & static front page.
  • is_singular() catches all "single" views, like a page, an attachment, a post, etc.
  • is_search() covers search result pages
  • is_404() catches everything ... that wasn't catched

So based on this list, you should be able to wrape up what you need - depending what "blog area pages" are for you.

As a little helper, you can use the functions from this answer that lists all conditionals that are true on a request. This should help you getting around it pretty quick.

Just upload it as a plugin. Deactivate it when you're done.


bit more completed with PHP function would possible include strpos($_SERVER['REQUEST_URI'], "blog")

final solution:

    function is_blog()
        return ( is_home() || is_single() || is_category() || is_archive() || strpos($_SERVER['REQUEST_URI'], "blog") );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.