Displays the expected read time in the blog post.

If you are running a wordpress blog, you may want to find another plug-in and snipt to encourage visitors to stay busy rather than Click to read posts. Today, visitors can get as much information as possible by simply browsing the page. It is very convenient to display the expected reading time of the post. In this way, visitors can know how long it takes to read topics of interest and obtain information. Ultimately, this will encourage bloggers to create more interesting and time-saving posts. In addition, blog owners can determine the best method by viewing statistics and comparing when visitors send other posts. The
Although some plug-ins do involve this feature, the WordPress feature that handles this feature is very simple. Therefore, to achieve this, you do not need to use other plug-ins to block blogs. Incorporate changes into the free WordPress twenty six theme for easy understanding. If (! Function_exists (\
\/**The
A function that estimates the read time for a given $content.
@Param string$content calculates the content of the read time.
@Paramint$wpm the expected number of words per minute for the reader.
@Returns int$time expected read time.
*\/The
Function content_estimated_reading_time ($content = ”, $wpm = 200){
$clean\u content= strip\u shortcodes ($content);
$clean\u content= strip\u tags ($clean\u content);
$word_count= str\u word_count ($clean\u content);
$time = ceil ($word_count\/ $wpm);
$output = \
$output. = ‘ Male ‘$ Time. ‘ Male ‘.’;
$output. = ‘ Male ‘ Esc\u attr\u (\
$output. = ‘ Male ‘;
Return $output;
}The
}This function allows two parameters for content ($content) and estimated words per reader ($wpm). For ordinary readers, the second parameter is set to 200, but can be set to different values. You can collect relevant useful information on the Internet. The
You must remove content from all content in the function except the word itself. Therefore, we will first use two functions (strip\u shortcodes and strip\u tags) to remove shortcut codes and tags. Then, you must count the words of the collated content. Therefore, the contents are saved in the $word_count variable. The function that calculates the words used here is str\u word\u count. To calculate the average read time, simply divide the number of words by the words read per minute. The ceil function used here is to round the result. The
The second part of the function is to output HTML, as well as subsequent time and text. To incorporate features into a theme, use the functions in the current theme. Just add it to the end of the PHP file. As you can see, the whole logic behind the average read time is very simple. But the function itself does nothing. Therefore, it must be called before it can be displayed in the blog list or in a single post. There are several ways to start the function call function. Three issues are discussed below. 1.eco generally speaking, the easiest way for most users is to call functions directly in the required files. For example, the template single used to display a single post. Suppose you need to call a function in a PHP file. It’s just
Opening the file and using the post content as a parameter means that the function must be environmentally friendly, as shown below: The
Of course this is single. If there are rings and all structures in the PHP file, but not in most cases. Examples of structures are as follows: 2. use modern and better coding themes of filters to separate these modules into different files. Therefore, it is better to use filters and add filter capabilities to return content. The topic of how to add filters has been widely discussed on the Internet. 3. in order to achieve more control, the existing functions can be better controlled to modify the output position, so this may be the best method. The Tweety six theme has the ability to print categories and labels for each post and individual posts in the list. These are 26 10 item classification functions. Simply copy the remaining tasks to complete the functions. Paste it into PHP, and modify the last part to call the function that expects the read time. The
Because we keep the same name for the function, I would like to briefly mention that we will redefine the original name. The modified functionality will now run in all locations in the theme. The changed function shall be:\/**
*Functions that redefine basic functions in the parent topic
*Finally, add the read time function
*\/The
Function 2016\entry\categories(){
$categories_list=get_the_categories_list (\u x (\
If ($categories\u list&&twentysixteen\u categorized\u blog()){
Printf (‘masculine%1$s masculine%2$s masculine’,
_X (\
$categories_list
);
}The
$tag_list=get_the_tag_list (\
If ($tags\u list& &! Is\wp\u error ($tags\u list)){
Printf (‘masculine%1$s masculine%2$s masculine’,
_X (\
$tags_list
);
}The
\/*Modify the code of this function**
Print content_established_reading_time (get_the_content());
}In this way, the read time of the part to which the tag and category belong is output. The
Male function of twenty six theme. The code in the PHP file must be: Male if (! Function_exists (‘content\u estimated\u reading\u time’){
\/**The
A function that estimates the read time for a given $content.
@Param string$content calculates the content of the read time.
@Param int$wpm expected number of words per minute for the reader.
@Returns int$time expected read time.
*\/The
Function content_estimated_reading_time ($content = ”, $wpm = 200){
$clean\u content = strip\u shortcodes ($content);
$clean\u content = strip\u tags ($clean\u content);
$word_count = str\u word_count ($clean\u content);
$time = ceil ($word_count \/ $wpm);
$output = \
$output. = ‘ Male ‘$ Time. ‘ Male ‘.’;
$output. = ‘ Male ‘ Esc\u attr\u (\
$output. = ‘ Male ‘;
Return $output;
}The
}The
\/**The
*In parent theme
Functions of basic functions in redefinition
*Finally, add the read time function
*\/The
Function 2016\entry\categories(){
$categories_list=get_the_categories_list (\u x (\
If ($categories_list&26-10- category blog (){
Printf (‘masculine%1$s masculine%2$s masculine’,
_X (\
$categories_list
);
}The
$tag_list=get_the_tag_list (\
If ($tags\u list & &! Is\wp\u error ($tags\u list)){
Printf (‘masculine%1$s masculine%2$s masculine’,
_X (\
$tags_list
);
}The
\/*Modify the code of this function**
Print content_established_reading_time (get_the_content());
}Whenever possible, perform this modification in the subtopics. The
Note that the best way to integrate function calls may vary when you add the expected read time function to another topic. Please take a moment to look at the steps we will take to find the best way. I hope this report can help. If you like this article, you can also confirm this article together! Create a block for Gutenberg editor and mark the release date as \

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *