Last active
October 17, 2021 11:35
-
-
Save EdwardBock/5618f06a1cde9cae5abe837c99b516db to your computer and use it in GitHub Desktop.
Add reading time to post content with a custom shortcode.
This file contains 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 | |
// [reading_time] | |
// [reading_time post_id="..."] | |
add_shortcode( 'reading_time', function($atts){ | |
$a = shortcode_atts( array( | |
'post_id' => false, | |
), $atts ); | |
$postId = $a['post_id'] ? intval($a['post_id']) : get_the_ID() | |
if(empty($postId)) return ""; | |
// https://gist.github.com/EdwardBock/fa659b67bcf4f568289d0c49c175f42b | |
return reading_time_get_content($postId); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment