WordPress plugin-free to achieve article readings

Original link: https://www.williamlong.info/archives/6920.html

WordPress.jpg

Generally, adding reading statistics for WordPress articles will use various statistical plug-ins, which consume system resources, and many plug-ins conflict with static or CACHE WordPress. Here is a way to share two paragraphs here to achieve WordPress article reading without plug-ins. The code for the number of times supports fully static WordPress for your reference.

Edit the template file of the article page and add the following HTML code where you need to display the number of readings:

<p>Read: <?php echo “<span id=\”span_views\”></span><script type=\”text/javascript\”>strBatchView=”;the_ID();echo “</script> ”; ?></p>

After that, add the following HTML code at the bottom of the article page template,

<script type=’text/javascript’>

var js = document.createElement(“script”);

js.src = “/wp-counter.php?post_id=” + escape(strBatchView);

document.getElementsByTagName(“body”)[0].appendChild(js);

</script>

Finally, download the JavaScript file of ” Static version of WP-PostViews ” and place the file in the root directory of the website.

In this way, the WordPress plugin-free article reading function can be realized, and the fully static WordPress system can be supported.

This article is reprinted from: https://www.williamlong.info/archives/6920.html
This site is for inclusion only, and the copyright belongs to the original author.