{"id":266,"date":"2023-10-20T13:39:36","date_gmt":"2023-10-20T13:39:36","guid":{"rendered":"https:\/\/wpshortcode.org\/?p=266"},"modified":"2023-10-20T13:39:37","modified_gmt":"2023-10-20T13:39:37","slug":"wp-statistics","status":"publish","type":"post","link":"https:\/\/wpshortcode.org\/wp-statistics\/","title":{"rendered":"WP Statistics Shortcode"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Below, you&#8217;ll find a detailed guide on how to add the <strong>WP Statistics Shortcode<\/strong> to your WordPress website, including its <strong>parameters<\/strong>, <strong>examples<\/strong>, and <strong>PHP function code<\/strong>. Additionally, we&#8217;ll assist you with common issues that might cause the WP Statistics Plugin shortcode not to show or not to work correctly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before starting, here is an overview of the WP Statistics Plugin and the shortcodes it provides:<\/p>\n\n\n<p>    <div class=\"plugin-info-box\">\n        <div class=\"top-main\">\n            <!-- SVG Image -->\n            <div class=\"plugin-image\">\n                <img decoding=\"async\" src=\"https:\/\/ps.w.org\/wp-statistics\/assets\/icon.svg?rev=2781181\" alt=\"Plugin Icon\" \/>\n            <\/div>\n            \n            <div class=\"plugin-descriptive-part\">\n                <!-- Plugin Name with Link -->\n\n                    <a class=\"plugin-title\" href=\"https:\/\/wordpress.org\/plugins\/wp-statistics\" target=\"_blank\" rel=\"noopener\">\n                        WP Statistics                    <\/a>\n\n\n                <!-- Plugin Description -->\n                <p class=\"plugin-description\">\n                    &quot;WP Statistics is a comprehensive plugin for your WordPress site that provides detailed and accurate site stats. Get insights on visitors, page views, and more with ease.&quot;                <\/p>\n            <\/div>\n        <\/div>\n\n        <!-- Rating and Additional Info -->\n        <div class=\"plugin-meta\">\n            <span class=\"plugin-rating\">\n                <span class='stars'>\u2605\u2605\u2605\u2605\u2729<\/span> (631)\n            <\/span>\n            <span class=\"plugin-active-installs\">\n                <strong>Active Installs<\/strong>: 600000+\n            <\/span>\n            <span class=\"plugin-tested\">\n                <strong>Tested with<\/strong>: 6.3.2            <\/span>\n            <span class=\"plugin-php-version\">\n                <strong>PHP Version<\/strong>: 5.6            <\/span>\n        <\/div>\n\n        <!-- List of Included Shortcodes -->\n        <div class=\"plugin-shortcodes\">\n            <strong>Included Shortcodes:<\/strong>\n            <ul>\n                <li>[wpstatistics]<\/li>            <\/ul>\n        <\/div>\n    <\/div>\n    <\/p>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">WP Statistics [wpstatistics] Shortcode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The WP-Statistics shortcode provides a flexible way to display various site statistics. It accepts attributes like &#8216;stat&#8217;, &#8216;time&#8217;, &#8216;provider&#8217;, &#8216;format&#8217;, and &#8216;id&#8217; to customize the output. \n\n\n\nDepending on the &#8216;stat&#8217; value, it can show users online, visits, visitors, page visits, searches, referrers, postcount, pagecount, commentcount, spamcount, usercount, postaverage, commentaverage, useraverage, and last post date. \n\nThe &#8216;format&#8217; attribute allows the output to be formatted in &#8216;i18n&#8217;, &#8216;english&#8217;, or &#8216;abbreviated&#8217; styles. The shortcode returns the result based on the provided attributes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode<\/strong>: <code>[wpstatistics]<\/code><\/p>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Parameters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here is a list of all possible wpstatistics shortcode parameters and attributes:<\/p>\n\n\n<ul>\n<li><code>stat<\/code> &#8211; Determines the type of statistics to display<\/li>\n<li><code>time<\/code> &#8211; Specifies the time frame for the statistics<\/li>\n<li><code>provider<\/code> &#8211; Defines the search engine provider for the statistics<\/li>\n<li><code>format<\/code> &#8211; Sets the format of the output numbers<\/li>\n<li><code>id<\/code> &#8211; Refers to the specific page or post ID for page visit statistics<\/li>\n<\/ul>\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Examples and Usage<\/h3>\n\n\n<p><strong>Basic example<\/strong> &#8211; Displaying the number of users online on your website<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"usersonline\"]<\/code><\/pre>\n\n\n<p><strong>Advanced examples<\/strong><\/p>\n<p>Displaying the number of visits to your website in the last week<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"visits\" time=\"week\"]<\/code><\/pre>\n\n\n<p>Displaying the number of visitors to your website from a specific provider (e.g., Google) in the last month, with the number formatted in international format<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"searches\" provider=\"google\" time=\"month\" format=\"i18n\"]<\/code><\/pre>\n\n\n<p>Displaying the number of visits to a specific page (e.g., with ID 123) in the last day<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"pagevisits\" id=\"123\" time=\"day\"]<\/code><\/pre>\n\n\n<p>Displaying the number of spam comments on your website, with the number formatted in English format<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"spamcount\" format=\"english\"]<\/code><\/pre>\n\n\n<p>Displaying the average number of posts per user on your website<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"postaverage\"]<\/code><\/pre>\n\n\n<p>Displaying the date of the last post on your website<\/p>\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">[wpstatistics stat=\"lpd\"]<\/code><\/pre>\n\n\n\n<div style=\"height:5px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">PHP Function Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In case you have difficulties debugging what causing issues with <code>[wpstatistics]<\/code> shortcode, check below the related PHP functions code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode line<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">add_shortcode('wpstatistics', array($this, 'shortcodes'));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Shortcode PHP function<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; light: false; title: ; toolbar: true; notranslate\" title=\"\">\nfunction shortcodes($atts)\n    {\n\n        if (!is_array($atts)) {\n            return;\n        }\n        if (!array_key_exists(&#039;stat&#039;, $atts)) {\n            return;\n        }\n\n        if (!array_key_exists(&#039;time&#039;, $atts)) {\n            $atts&#91;&#039;time&#039;] = null;\n        }\n        if (!array_key_exists(&#039;provider&#039;, $atts)) {\n            $atts&#91;&#039;provider&#039;] = &#039;all&#039;;\n        }\n        if (!array_key_exists(&#039;format&#039;, $atts)) {\n            $atts&#91;&#039;format&#039;] = null;\n        }\n        if (!array_key_exists(&#039;id&#039;, $atts)) {\n            $atts&#91;&#039;id&#039;] = -1;\n        }\n\n        $formatnumber = array_key_exists(&#039;format&#039;, $atts);\n\n        switch ($atts&#91;&#039;stat&#039;]) {\n            case &#039;usersonline&#039;:\n                $result = wp_statistics_useronline();\n                break;\n\n            case &#039;visits&#039;:\n                $result = wp_statistics_visit($atts&#91;&#039;time&#039;]);\n                break;\n\n            case &#039;visitors&#039;:\n                $result = wp_statistics_visitor($atts&#91;&#039;time&#039;], null, true);\n                break;\n\n            case &#039;pagevisits&#039;:\n                $result = wp_statistics_pages($atts&#91;&#039;time&#039;], null, $atts&#91;&#039;id&#039;]);\n                break;\n\n            case &#039;searches&#039;:\n                $result = wp_statistics_searchengine($atts&#91;&#039;provider&#039;], $atts&#91;&#039;time&#039;]);\n                break;\n\n            case &#039;referrer&#039;:\n                $result = wp_statistics_referrer($atts&#91;&#039;time&#039;]);\n                break;\n\n            case &#039;postcount&#039;:\n                $result = Helper::getCountPosts();\n                break;\n\n            case &#039;pagecount&#039;:\n                $result = Helper::getCountPages();\n                break;\n\n            case &#039;commentcount&#039;:\n                $result = Helper::getCountComment();\n                break;\n\n            case &#039;spamcount&#039;:\n                $result = Helper::getCountSpam();\n                break;\n\n            case &#039;usercount&#039;:\n                $result = Helper::getCountUsers();\n                break;\n\n            case &#039;postaverage&#039;:\n                $result = Helper::getAveragePost();\n                break;\n\n            case &#039;commentaverage&#039;:\n                $result = Helper::getAverageComment();\n                break;\n\n            case &#039;useraverage&#039;:\n                $result = Helper::getAverageRegisterUser();\n                break;\n\n            case &#039;lpd&#039;:\n                $result       = Helper::getLastPostDate();\n                $formatnumber = false;\n                break;\n        }\n\n        if ($formatnumber) {\n            switch (strtolower($atts&#91;&#039;format&#039;])) {\n                case &#039;i18n&#039;:\n                    $result = number_format_i18n($result);\n\n                    break;\n                case &#039;english&#039;:\n                    $result = number_format($result);\n\n                    break;\n                \/\/ In this line a new function is added so that the abbreviation of larger numbers is displayed with the symbols 1K, 1M or 1B\n                case &#039;abbreviated&#039;:\n                    $result = $this-&gt;formatNumber($result);\n                    break;\n            }\n        }\n\n        return $result;\n    }\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>Code file location<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\">wp-statistics\/wp-statistics\/includes\/class-wp-statistics-shortcode.php<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you&#8217;ve learned how to embed the <strong>WP Statistics Plugin shortcode<\/strong>, understood the parameters, and seen code examples, it&#8217;s easy to use and debug any issue that might cause it to &#8216;not work&#8217;. If you still have difficulties with it, don&#8217;t hesitate to leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below, you&#8217;ll find a detailed guide on how to add the WP Statistics Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we&#8217;ll assist you with common issues that might cause the WP Statistics Plugin shortcode not to show or not to work correctly. Before starting, here is an overview [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"name":"WP Statistics","slug":"","version":"14.2","author":"<a href=\"https:\/\/veronalabs.com\/\">VeronaLabs<\/a>","icons":"https:\/\/ps.w.org\/wp-statistics\/assets\/icon.svg?rev=2781181","plugin_tags":"{\"analytics\":\"analytics\",\"statistics\":\"statistics\",\"stats\":\"stats\",\"visit\":\"Visit\",\"wordpress-analytics\":\"WordPress analytics\"}","author_profile":"https:\/\/profiles.wordpress.org\/mostafas1990\/","requires":"4.4","tested":"6.3.2","requires_php":"5.6","rating":82,"num_ratings":631,"active_installs":600000,"downloaded":20355643,"last_updated":"2023-10-09 10:40am GMT","added":"2011-03-20","homepage":"https:\/\/wp-statistics.com\/","short_description":"This plugin gives you the complete information on your website&#039;s visitors.","description":"\"WP Statistics is a comprehensive plugin for your WordPress site that provides detailed and accurate site stats. Get insights on visitors, page views, and more with ease.\"","shortcodes":"[\"wpstatistics\"]","footnotes":""},"categories":[1],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-standard","hentry","category-plugins"],"_links":{"self":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/comments?post=266"}],"version-history":[{"count":1,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":272,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/posts\/266\/revisions\/272"}],"wp:attachment":[{"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/media?parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/categories?post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpshortcode.org\/wp-json\/wp\/v2\/tags?post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}