Created
May 25, 2026 12:10
-
-
Save dhirenpatel22/8b5d9d7b09e7dc969b4ee2ea2df43e04 to your computer and use it in GitHub Desktop.
Yoast SEO Reading Time Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Shortcode to display Yoast estimated reading time | |
| * Usage: [yoast_reading_time] | |
| */ | |
| function yoast_reading_time_shortcode() { | |
| // Check if the Yoast function exists to prevent fatal errors | |
| if ( function_exists( 'YoastSEO' ) ) { | |
| $reading_time = YoastSEO()->meta->for_current_page()->estimated_reading_time_minutes; | |
| if ( $reading_time ) { | |
| return '<span class="yoast-reading-time">' . $reading_time . ' min read</span>'; | |
| } | |
| } | |
| return ''; | |
| } | |
| add_shortcode( 'yoast_reading_time', 'yoast_reading_time_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment