You could hook into template_redirect and execute a helper function:
add_action( 'template_redirect', 'wpse_75558_count' );
function wpse_75558_count()
{
if ( is_singular() )
setPostViews( get_the_ID() );
}
To display the post views, you have to use a later hook. I would recommend the_content:
add_filter( 'the_content', 'wpse_75558_show_count' );
function wpse_75558_show_count( $content )
{
$count = getPostViews( get_the_ID() );
if ( ! is_numeric( $count ) )
$count=""; // prevent errors showing to visitors
else
$count = "<p class="view-count">Views: $count</p>";
return $content . $count;
}
Just an idea, I haven’t tested the code.
Related Posts:
- Count singular post views automatically
- Action hook ‘wp’ firing twice… why?
- Alternate custom content in the loop
- Custom function for “Submit for Review” hook
- How can I hook into creating a new post and execute wp_die(), before the post is inserted into the database?
- Double count view in archive.php
- How can i do something after head like adding a hook for after head but before post
- Adding buttons to Add New Post and Add New Page
- How to access $post from a callback function
- Copy post to separate database with “add_action(….)”
- Call Web Services on post first publish
- What does WordPress do if I save a post without content/title? [duplicate]
- Divs appearing everywhere in post content
- Automatically set post_parent value
- Is there a way to know when a page has been updated and do some action only once?
- Is update_post_meta used when save_post action hook is invoked?
- Retrieve posts inside foundation tabs and tab-content split by 3 per row
- Alternative content between posts no repetition
- Grab meta data before post is saved
- How to control Post view count incresing in sidebar widget posts too?
- How to get total posts count for each date?
- Modify upload directory to use post category slug in file path on multisite installation
- Comment count next to post title?
- Override the default number of posts to show for a single loop?
- flush_rewrite_rules on save_post Does Not Work on First Post Save
- How to add a “publish” link to the quick actions
- Better post meta efficiency?
- Looping through posts per category gives same posts for each category
- Set font size automatically according to number of words in post
- Display All Sticky Post Before Regular Post
- How to have different content in the loop and single
- Filter post before *editing*
- Repost post on specific date every year
- How to filter content post only on save
- Display Latest Post from all Categories
- custom wordpress post loop – hide iframe content
- Divide Loop Into Days & Categories
- Contact form 7 post loop [closed]
- How to display different number of posts
- WP Query – duplicated posts once including tags in search results
- wp_tag_cloud() and the_taxonomies() work but not the_tag()
- How to retrieve the postID in a “image_send_to_editor” hook function?
- Register post status, exclude from searches
- Show all posts in sidebar in single.php
- Split WordPress Latest Posts in Multiple Columns and Rows with one single loop [closed]
- Avoid duplicate post from same Taxonomy
- Alternate row and columns every X posts
- Best way to assign post position in a news site homepage? (no categories, no sticky posts)
- How do I restart my loop with get_next_post()?
- use wpml_post_language_details function other plugin based on $post->ID [closed]
- Posts will not display on page-mypage.php
- Show posts count for Categories and Tags in wp_nav_menu
- Change all author links in Blog roll
- Showing categories and subcategories with posts
- why the same code got different results when using query_posts in functions.php and index.php
- older blog posts not showing in new theme
- How to only publish posts with image in it
- Modify posts listing at back end
- WordPress Query Posts From Category Post on Static Page
- How do I insert a after every 5 posts in a WordPress Loop that infinitely loads posts?
- Loop through posts? Want to remove extra newlines in actual post HTML/content on backend
- WP_Query: Show 10 posts in date order, first three random
- How include css class based on post ( in loop ) slug?
- WordPress Loop: How to display recent posts in multiple divs
- Cannot implement byline into posts container in single.php
- How to check if there are posts with the same tag
- Exists filter or action that change Add New Post link?
- Accessing Post ID Within Loop
- WP_Query of Category Not Showing First Post
- How come this loop is not working? [closed]
- Count user posts and store the number for later use
- Using the loop to set locations for all posts on a single google map
- Defining ‘last’ class on foreach blog posts
- Actions to use when flushing cache (when posts are added / deleted / modified)
- Separate top level categories on archive-product.php by meta
- While loop in functions.php outputting the_title() of each post on frontpage
- Shortcode for Comments and Comment Boxes in Post Loop
- Permalink Short code showing unnecessary link text inside the loop
- Author post count in category
- Show post count in custom taxonomy page
- Double loop output
- Display number of post published every day
- post->ID displays the same ID number for every post
- Posts are not showing up on next page.
- count_posts to a standalone link
- How to get the postID inside ‘content_save_pre’? Other hook?
- Post are not showing up
- How to make post button to a random post
- Advanced Post Display/Pagination/Ordering
- How to inject a post within a loop
- Sort by category and then date?
- Loop not allowing infinite scroll after post per page limit
- How to limit the number of posts a user can publish based on user type
- ho can I get the number of the current post instead of the post id?
- How to show only the date, the title and a little “summary” of my WordPress post in my custom theme?
- posts_per_page – Repeats only first posts ‘post__in’ array
- blog post displaying within older post – loop issue?
- Count the number of matching post names in foreach loop
- Global $post value outside the loop
- List of published post dates only outputting one date