Pages

Saturday, June 1, 2013

Website visit count in wordpress


We can track wordpress visit count using function.php. Just use the following function in function.php
<?php
function visit_count()
{
// just increment and display a counter at the bottom of each page
if(!isset($_SESSION['hit_count']))
{
$count=1+intval(get_option('site_visit_count'));
update_option('site_visit_count',$count);
}
$_SESSION['hit_count']=$count=get_option('site_visit_count');
$count=number_format($count);
echo << $count
HTML_CODE;
}
?>
Call function "visit_count()" in our site to display the total number of visitors in your site. Sometimes session is disabled in your wordpress site, then the code will not work perfectly. We need to enable session in wordpress. Check the following link to know how to enable session in wordpress.
Enable session in wordpress

No comments:

Post a Comment