Does wordpress have a post hit counter?

Not in core. You can use post meta to store this information on page loads. If you have caching plugins enabled, you might want to increment the hit counter with an AJAX call, otherwise you can just add this directly in your single.php and page.php templates:

//Add to functions.php
function get_hits(){
    global $post;
    $hits = get_post_meta($post->ID, '_hit-counter', true);
    return $hits;
}

function update_hits($count){
    global $post;
    $count = $count ? $count : 0;
    $hits = update_post_meta($post->ID, '_hit-counter', $count++);
    return $hits;
}

//Usage within the loop
update_hits(get_hits());

Leave a Comment