How can I tell my wordpress to do something in the header if its a blog page?

In a previous post (Don’t show this if the url contains the following) I asked how I would go about having my header echo a div if the user loaded a URL with /blog in the header.

What I didn’t take into consideration, was that I don’t want the div to display if its not just got /blog in the url, but if its any blog post, not just the index page of the blogs.

Read More

How do I run a bit of code from my header.php if the page I’m looking at is a blog post?

Related posts

Leave a Reply

2 comments

  1. You would use the WordPress functions is_single() and is_page.

    if(!is_single() && !is_page() && !is_home() && !is_archive())
    {
    /* This will not display for any post, page, the home page, or an archive.
     You can remove each is statement according to your needs */
    }
    

    For only posts, only use is_single, the same for page, home, and archive.

    The full listing of is_statements can be found here. Here are some others:

    is_home() : Home Page
    is_front_page :  Front Page
    is_single() :  Single Post
    is_admin() : Admin Panel
    is_sticky() : Sticky Post
    is_page() : Page
    is_category
    is_tag
    is_author