AI Verified

Name

Display Estimated Read Time For Blog Posts

About

Display the estimated read time of a post with a shortcode. This code snippet produces a shortcode to display the estimated reading time for a post. It strips HTML tags, counts the words, and divides by 200 (words per minute) to get the reading time in minutes.

Language

PHP

Rating

Voted: 5 by 5 user(s)

How to Setup Snippet

1. Activate your code snippet. 2. In your posts or pages, add [read-time] where you want the reading time to be displayed. OR To display this in a loop grid, you can call do_shortcode('[read-time]') in your theme's template files, where you list your posts. *Test this on a staging environment before deploying it on your live site.

Codevault

Nestwise

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

02/02/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Display Estimated Read Time For Blog Posts

 
                    
1function nestwise_calculate_reading_time( $content ) {
2 $word_count = str_word_count( strip_tags( $content ) );
3 $reading_time = ceil( $word_count / 200 );
4 return $reading_time;
5}
6 
7function nestwise_reading_time_shortcode() {
8 global $post;
9 $reading_time = nestwise_calculate_reading_time( $post->post_content );
10 return '<span class="reading-time">Read Time: ' . $reading_time . ' minute(s)</span>';
11}
12 
13add_shortcode( 'read-time', 'nestwise_reading_time_shortcode' );

5

Comments

  • AR

    6 months ago

    Nice :-)

Related Snippets

Please see some snippets below related to this snippet..

General

AI Verified

17

Convert To WebP

Added: 7 months ago

Last Updated: 3 weeks ago

<p>Snippet to convert JPG / PNG / Gif to WebP automatically on upload. Used GD or ImageMagick</p>

General

Unverified

0

QuizLogic

Added: 2 months ago

Last Updated: 2 months ago

General

AI Verified

0

Simple Project Timer

Added: 1 month ago

Last Updated: 4 days ago

<p>This snippet provides a project timer functionality within the WordPress admin dashboard. It allows users to:<br />- Start, stop, and log time spent on various tasks.<br />- Manually add time entri...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

General

AI Verified

5

Display Estimated Read Time For Blog Posts

Added: 6 months ago

Last Updated: 5 months ago

Display the estimated read time of a post with a shortcode. This code snippet produces a shortcode to display the estimated reading time for a post. It strips HTML tags, counts the words, and divi...

WordPress Admin

AI Verified

1

Display External Server IP

Added: 4 months ago

Last Updated: 3 months ago

This WordPress code snippet enhances the admin dashboard by adding a custom item to the WordPress admin bar labeled "Check External IP". This feature allows administrators to fetch and display the ext...

General

AI Verified

0

What's My IP? Display the current users IP address with shortcode

Added: 4 months ago

Last Updated: 4 months ago

Display the users current IP address with shortcode [my-ip]