When WordPress is editing logs in the background, there is a word count in the lower left corner of the editing box, but it is only displayed in the background. Can I add the word count statistics function in the front? After studying the program source file, we found that the Chinese version of WP background word count function is achieved through the wp-content \ ages directory zh_CN-word-count.js, that is, do not know how to call. I searched the internet and found two code provided by foreigners:
1. Add the following code to the topic's functions. php file:
Function count_words ($ str ){
$ Words = 0;
$ Str = eregi_replace ("+", "", $ str );
$ Array = explode ("", $ str );
For ($ I = 0; $ I <count ($ array); $ I ++)
{
If (eregi ("[0-9A-Za-z À-öø-limit]", $ array [$ I])
$ Words ++;
}
Return $ words;
}
In single. php, add:
Word count: <? Php echo count_words ($ post-> post_content);?>
Original
2. Add the following code to the functions. php file. This method is different from the above, and an estimated reading time is added:
// Custom functions
// START: Show word count
Function show_post_word_count (){
Ob_start ();
The_content ();
$ Content = ob_get_clean ();
Return sizeof (explode ("", $ content ));
}
// END: Show word count
// START: Estimated reading time
If (! Function_exists ('est _ read_time ')):
Function est_read_time ($ return = false ){
$ Wordcount = round (str_word_count (get_the_content (),-2 );
$ Minutes_fast = ceil ($ wordcount/250 );
$ Minutes_slow = ceil ($ wordcount/150 );
If ($ wordcount <= 150 ){
$ Output = _ ("<1 minute ");
} Else {
$ Output = sprintf (_ ("% s-% s minutes"), $ minutes_fast, $ minutes_slow );
}
Echo $ output;
}
Endif;
If (! Function_exists ('est _ the_content ')):
Function est_the_content ($ orig ){
// Prepend the reading time to the post content
Return est_read_time (true). "\ n". $ orig;
}
Endif;
// END: Estimated reading time
Similarly, in single. php, you want to add:
The following <? Php echo show_post_word_count ();?> Words shoshould take about <? Php echo est_read_time ();?> To read.
Original
Unfortunately, the above two methods are ineffective in Chinese Character statistics. They are only suitable for English-only websites. No articles related to Chinese Blog word count statistics have been found on the Internet.
Excerpted from zhiwubird