WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a hook such that when visitor lands on any of the post (not page), I need to record a hit.

How can I find whether the request is for post, and is there any hook to find if the loaded content is post, and if yes, what is post id

share|improve this question
up vote 1 down vote accepted

something like this will work:

function record_hit_if_post(){
    global $wp_query;
        // single post's ID:
        // $wp_query->post->ID;
add_filter('template_redirect', 'record_hit_if_post');
share|improve this answer
is_single might come up with page too, don't you think so? – I-M-JM May 3 '11 at 2:22
no, just single post. is_page == 1 on a page – Milo May 3 '11 at 3:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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