Add Word Count to Single Posts in WordPress

Today, We want to share with you Add Word Count to Single Posts in WordPress.In this post we will show you How to Track Your Word Count in WordPress Posts, hear for How to Set a Minimum Word Count for WordPress Posts we will give you demo and example for implement.In this post, we will learn about Count Words in WordPress Post Content with an example.

Add Word Count to Single Posts in WordPress

There are the Following The simple About Add Word Count to Single Posts in WordPress Full Information With Example and source code.

Read Also:  PHP Accelerator in Xampp - install Alternative

As I will cover this Post with live Working example to develop Word limit in post_content after more tag, so the some major files and Directory structures for this example is following below.

The Basic WordPress Word Count Function

functions.php

function pakainfo_word_count() {
   return sprintf(
      __( '%s words', 'text-domain' ),
      str_word_count( strip_tags( get_post_field( 'post_content', get_the_ID() ) ) )
   );
}

Displaying the Word Count in wordpress website

display on the left with the post’s meta data,

<div class="col-md-3 entry-meta">
   <p><i class="fa fa-bookmark"></i> <?php _e( 'Posted in ', 'thems_name' ); the_category( ', ' ); ?></p>

   <?php if ( comments_open() ) { ?>
   <p><i class="fa fa-comments"></i> <?php comments_popup_link( __( '0 Comments', 'thems_name' ), __( '1 Comment', 'thems_name' ), __( '% Comments', 'thems_name' ), '', '' ); ?></p>
   <?php } ?>
</div>

Count Words in WordPress Post Content

new function

<p><?php echo pakainfo_word_count(); ?></p>

Add it all together:

Read Also:  How to Auto Post on Twitter using PHP API

<div class="col-md-3 entry-meta">
   <p><i class="fa fa-bookmark"></i> <?php _e( 'Posted in ', 'thems_name' ); the_category( ', ' ); ?></p>
   <p><?php echo pakainfo_word_count(); ?></p>

   <?php if ( comments_open() ) { ?>
   <p><i class="fa fa-comments"></i> <?php comments_popup_link( __( '0 Comments', 'thems_name' ), __( '1 Comment', 'thems_name' ), __( '% Comments', 'thems_name' ), '', '' ); ?></p>
   <?php } ?>
</div>

Web Programming Tutorials Example with Demo

Read :

Read Also:  How to change date format in PHP?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Word Count to Single Posts.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Load multiple views in same controller
  2. Read Also:  Chosen Ajax Autocomplete Textbox using jQuery, PHP
  3. Read Also:  How to Create, Access and Destroy Sessions in Laravel
  4. Read Also:  MySQL Multicolumn UPDATE JOIN subquery
  5. Read Also:  vue router change route programmatically
  6. Read Also:  Angular 6 Application Architecture with Multiple Modules
  7. Read Also:  Strong Random Password Generator Using VueJS
  8. Read Also:  How to change date format in PHP?
  9. Read Also:  vue router change route programmatically
  10. Read Also:  Angular 6 Application Architecture with Multiple Modules
CLOSEX