Below, you’ll find a detailed guide on how to add the WPS Visitor Counter Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WPS Visitor Counter Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the WPS Visitor Counter Plugin and the shortcodes it provides:

"WPS Visitor Counter Plugin is a dynamic WordPress tool that keeps tabs on your website's traffic, offering insightful data on visitor count in a user-friendly interface."
- [wps_visitor_counter]
WPS Visitor Counter [wps_visitor_counter] Shortcode
The WPS Visitor Counter shortcode is used to display visitor statistics on a WordPress site. It retrieves and displays data like total views, users today, yesterday, last 7 days, this month, this year, and total users. It also shows views today, yesterday, last 7 days, this month, this year, total views, and current online users. Additionally, it displays the user’s IP address and server time.
Shortcode: [wps_visitor_counter]
Examples and Usage
Basic example – Displaying the visitor counter on your website
[wps_visitor_counter]
PHP Function Code
In case you have difficulties debugging what causing issues with [wps_visitor_counter]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wps_visitor_counter', 'wps_add_visitor_counter' );
Shortcode PHP function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | function wps_add_visitor_counter() { global $wpdb ; $wps_option_data = wps_visitor_option_data(1); $wps_display_field = $wps_option_data [ 'display_field' ]; $wps_display_field_arr = explode ( "," , $wps_display_field ); $fontcolor = $wps_option_data [ "font_color" ]; $style = $wps_option_data [ "style" ]; $align = $wps_option_data [ "visitor_wpsvc_align" ]; $user_start = $wps_option_data [ "user_start" ]; $views_start = $wps_option_data [ "views_start" ]; $ip = wps_getRealIpAddr(); // Getting the user's computer IP $date = date ( "Y-m-d" ); // Getting the current date $date_year_month = date ( "Y-m" ); $date_year = date ( "Y" ); $yesterday_date = date ( 'Y-m-d' , strtotime ( "-1 days" )); $timeBefore = time() - 300; $ext = ".gif" ; //image print // UPDATE PLAN $user_total = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "`" ); if ( $user_start ==NULL) { $total_user_views = sprintf( "%06d" , $user_total ); } else { $total_user_views = sprintf( "%06d" , $user_total + $user_start ); } $wps_style = explode ( '/' , $style ); if ( $wps_style [0] == 'image' ) { for ( $i = 0; $i <= 9; $i ++) { $total_user_views = str_replace ( $i , "<img src='" . plugins_url ( "styles/$style/$i$ext" , __FILE__ ) . "' alt='$i'>" , $total_user_views ); } } elseif ( $wps_style [0] == 'text' ) { /*$total_user_views = intval($total_user_views);*/ /*return $total_user_views;*/ $total_user_views_array = array_map ( 'intval' , str_split ( $total_user_views )); $total_user_views = '<div class="wps_text_glowing ' . $wps_style [1].'"> <span> '.$total_user_views_array[0].' </span> <span> '.$total_user_views_array[1].' </span> <span> '.$total_user_views_array[2].' </span> <span> '.$total_user_views_array[3].' </span> <span> '.$total_user_views_array[4].' </span> <span> '.$total_user_views_array[5].' </span> </div>'; ?> <?php } //image $imgvisit = "<img src='" .plugins_url ('counter/user_today.png ' , __FILE__ ). "' >"; $img_visit_yesterday = "<img src='" .plugins_url ('counter/user_yesterday.png ' , __FILE__ ). "' >"; $img_visit_7days = "<img src='" .plugins_url ('counter/7days_user.png ' , __FILE__ ). "' >"; $img_visit_30days = "<img src='" .plugins_url ('counter/30days_user.png ' , __FILE__ ). "' >"; $img_visit_month = "<img src='" .plugins_url ('counter/user_month.png ' , __FILE__ ). "' >"; $img_visit_year = "<img src='" .plugins_url ('counter/user_year.png ' , __FILE__ ). "' >"; $img_visit_total = "<img src='" .plugins_url ('counter/user_total.png ' , __FILE__ ). "' >"; $imgviews = "<img src='" .plugins_url ('counter/views_today.png ' , __FILE__ ). "' >"; $img_views_yesterday = "<img src='" .plugins_url ('counter/views_yesterday.png ' , __FILE__ ). "' >"; $img_views_7days = "<img src='" .plugins_url ('counter/7days_views.png ' , __FILE__ ). "' >"; $img_views_30days = "<img src='" .plugins_url ('counter/30days_views.png ' , __FILE__ ). "' >"; $img_views_month = "<img src='" .plugins_url ('counter/views_month.png ' , __FILE__ ). "' >"; $img_views_year = "<img src='" .plugins_url ('counter/views_year.png ' , __FILE__ ). "' >"; $imgtotalviews = "<img src='" .plugins_url ('counter/views_total.png ' , __FILE__ ). "' >"; $imgonline = "<img src='" .plugins_url ('counter/whos_online.png ' , __FILE__ ). "' >"; //style and widgetne if ( $align ) $align = "text-align: $align;" ; if ( $fontcolor ) $fontcolor = "color: $fontcolor;" ; if ( $align || $fontcolor ) $style = "style='$align $fontcolor'" ; $wps_return = "<div id='mvcwid'" . $style . ">" ; ?> <?php if ( $wps_option_data [ 'visitor_title' ] != "" ){ $visitor_title = "<h3 class='wps_visitor_title'>" .esc_html( $wps_option_data [ 'visitor_title' ], 'wps-visitor-counter' ). "</h3>" ; $wps_return = $wps_return . $visitor_title ; } $wps_return = $wps_return . "<div id=\"wpsvccount\">" . $total_user_views ."</div> <div id=\ "wpsvctable\">" ; ?> <?php if (in_array( "today_user" , $wps_display_field_arr )) { $user_today = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` = '$date'" ); $wps_return = $wps_return . "<div id=\"wpsvcvisit\" " . $style . ">" . $imgvisit . " " .esc_html__( 'Users Today' , 'wps-visitor-counter' ). " : " . $user_today . "</div>" ; ?> <?php } ?> <?php if (in_array( "yesterday_user" , $wps_display_field_arr )) { $user_yesterday = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` = '$yesterday_date'" ); $wps_return = $wps_return . "<div id=\"wpsvcyesterday\" " . $style . ">" . $img_visit_yesterday . " " .esc_html__( 'Users Yesterday' , 'wps-visitor-counter' ). " : " . $user_yesterday . "</div>" ; ?> <?php } ?> <?php if (in_array( "last7_day_user" , $wps_display_field_arr )) { $user_last_7days = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` >= DATE(NOW()) - INTERVAL 7 DAY" ); $wps_return = $wps_return . "<div id=\"wpsvcyesterday\" " . $style . ">" . $img_visit_7days . " " .esc_html__( 'Users Last 7 days' , 'wps-visitor-counter' ). " : " . $user_last_7days . "</div>" ; ?> <?php } ?> <?php if (in_array( "last30_day_user" , $wps_display_field_arr )) { $user_last_30days = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` >= DATE(NOW()) - INTERVAL 30 DAY" ); $wps_return = $wps_return . "<div id=\"wpsvcyesterday\" " . $style . ">" . $img_visit_30days . " " .esc_html__( 'Users Last 30 days' , 'wps-visitor-counter' ). " : " . $user_last_30days . "</div>" ; ?> <?php } ?> <?php if (in_array( "month_user" , $wps_display_field_arr )) { $user_month = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` LIKE '$date_year_month%'" ); $wps_return = $wps_return . "<div id=\"wpsvcmonth\" " . $style . ">" . $img_visit_month . " " .esc_html__( 'Users This Month' , 'wps-visitor-counter' ). " : " . $user_month . "</div>" ; ?> <?php } ?> <?php if (in_array( "year_user" , $wps_display_field_arr )) { $user_year = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` LIKE '$date_year%'" ); $wps_return = $wps_return . "<div id=\"wpsvcyear\" " . $style . ">" . $img_visit_year . " " .esc_html__( 'Users This Year' , 'wps-visitor-counter' ). " : " . $user_year . "</div>" ; ?> <?php } ?> <?php if (in_array( "total_user" , $wps_display_field_arr )) { if ( $user_start ==NULL) { $total_user = $user_total ; } else { $total_user = $user_total + $user_start ; } $wps_return = $wps_return . "<div id=\"wpsvctotal\" " . $style . ">" . $img_visit_total . " " .esc_html__( 'Total Users' , 'wps-visitor-counter' ). " : " . $total_user . "</div>" ; ?> <?php } ?> <?php if (in_array( "today_view" , $wps_display_field_arr )) { $views_today = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` = '$date'" ); $wps_return = $wps_return . "<div id=\"wpsvcviews\" " . $style . ">" . $imgviews . " " .esc_html__( 'Views Today' , 'wps-visitor-counter' ). " : " . $views_today . "</div>" ; ?> <?php } ?> <?php if (in_array( "yesterday_view" , $wps_display_field_arr )) { $views_yesterday = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` = '$yesterday_date'" ); if ( $views_yesterday == "" ) { $views_yesterday ==0; } $wps_return = $wps_return . "<div id=\"wpsvcviews\" " . $style . ">" . $img_views_yesterday . " " .esc_html__( 'Views Yesterday' , 'wps-visitor-counter' ). " : " . $views_yesterday . "</div>" ; ?> <?php } ?> <?php if (in_array( "last7_day_view" , $wps_display_field_arr )) { $views_last7_days = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` >= DATE(NOW()) - INTERVAL 7 DAY" ); $wps_return = $wps_return . "<div id=\"wpsvcyesterday\" " . $style . ">" . $img_views_7days . " " .esc_html__( 'Views Last 7 days' , 'wps-visitor-counter' ). " : " . $views_last7_days . "</div>" ; ?> <?php } ?> <?php if (in_array( "last30_day_view" , $wps_display_field_arr )) { $views_last30_days = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` >= DATE(NOW()) - INTERVAL 30 DAY" ); $wps_return = $wps_return . "<div id=\"wpsvcyesterday\" " . $style . ">" . $img_views_30days . " " .esc_html__( 'Views Last 30 days' , 'wps-visitor-counter' ). " : " . $views_last30_days . "</div>" ; ?> <?php } ?> <?php if (in_array( "month_view" , $wps_display_field_arr )) { $views_month = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` LIKE '$date_year_month%'" ); $wps_return = $wps_return . "<div id=\"wpsvcviews\" " . $style . ">" . $img_views_month . " " .esc_html__( 'Views This Month' , 'wps-visitor-counter' ). " : " . $views_month . "</div>" ; ?> <?php } ?> <?php if (in_array( "year_view" , $wps_display_field_arr )) { $views_year = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `date` LIKE '$date_year%'" ); $wps_return = $wps_return . "<div id=\"wpsvcviews\" " . $style . ">" . $img_views_year . " " .esc_html__( 'Views This Year' , 'wps-visitor-counter' ). " : " . $views_year . "</div>" ; ?> <?php } ?> <?php if (in_array( "total_view" , $wps_display_field_arr )) { $totalviews = $wpdb ->get_var( "SELECT SUM(`views`) FROM `" . WPS_VC_TABLE_NAME . "`" ); if ( $views_start !=NULL) { $totalviews = $totalviews + $views_start ; } $wps_return = $wps_return . "<div id=\"wpsvctotalviews\" " . $style . ">" . $imgtotalviews . " " .esc_html__( 'Total views' , 'wps-visitor-counter' ). " : " . $totalviews . "</div>" ; ?> <?php } ?> <?php if (in_array( "online_view" , $wps_display_field_arr )) { $total_online = $wpdb ->get_var( "SELECT COUNT(`views`) FROM `" . WPS_VC_TABLE_NAME . "` WHERE `online` > '$timeBefore'" ); $wps_return = $wps_return . "<div id=\"wpsvconline\" " . $style . ">" . $imgonline . " " .esc_html__( 'Who\'s Online' , 'wps-visitor-counter' ). " : " . $total_online . "</div>" ; ?> <?php } $wps_return = $wps_return . "</div>" ; ?> <?php if (in_array( "ip_display" , $wps_display_field_arr )) { $wps_return = $wps_return . "<div id=\"wpsvcip\">" . $img_visit_year . " " .esc_html__( 'Your IP Address' , 'wps-visitor-counter' ). " : " . $ip . "</div>" ; ?> <?php } ?> <?php if (in_array( "server_time" , $wps_display_field_arr )) { $wps_return = $wps_return . "<div id=\"wpsvcdate\">" . $img_visit_year . " " .esc_html__( 'Server Time' , 'wps-visitor-counter' ). " : " . $date . "</div>" ; ?> <?php } ?> <?php if ( $wps_option_data [ 'show_powered_by' ] == 1) { $wps_return = $wps_return . "<div id=\"wpsvcattribution\" " . $style . "><small>Powered By <a href=\"https://techmix.xyz/\" rel=\"nofollow\">WPS Visitor Counter</a></small></div>" ; ?> <?php } $wps_return = $wps_return . "</div>" ; return $wps_return ; ?> <?php } |
Code file location:
wps-visitor-counter/wps-visitor-counter/wps-visitor-counter.php
Conclusion
Now that you’ve learned how to embed the WPS Visitor Counter Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply