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 using function.php

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.