I'm making a plugin that counts the number of times a visitor visits my site. I want to run the code in the plugin once per page load. What's a good action hook I can use ?
|
Basic idea is to use javascript to make an AJAX call back to the site which in turn save the hit because if you use PHP alone, then hits for cached pages won't be counted because no PHP is processed at that time. Study the code of WP-Postviews plugin http://lesterchan.net/portfolio/programming/php/#wp-postviews Edit: Hook may be fired twice in Firefox because it prefetches URL specified in HTML source as
Use this to remove that line from source
|
|||||||
|
|
@Ashfame is right with what he wrote. About your hook (we don't know which one you're using - firing twice sounds strange): |
|||
|
|
|
The way I would do it is not using any hooks at all. Just because Wordpress provides action and filter hooks does not mean you have to use them. In your footer.php file, add the following before the tag.
Then in your functions.php add this function:
Some would argue that this is too manual for Wordpress, but I've been using Wordpress for years, I use it on every single project I basically work on and sometimes it's easier to use a straight up function as opposed to using an action or filter. |
|||
|
