Last active
October 17, 2021 11:34
-
-
Save EdwardBock/fa659b67bcf4f568289d0c49c175f42b to your computer and use it in GitHub Desktop.
Public render function of the reading time plugin with overwritable template
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 | |
function reading_time_render($post_id){ | |
// https://medium.com/write-better-wordpress-code/do-not-use-post-meta-fec12a7661 | |
$db = new \PublicFunctionOrg\WordPress\ReadingTime\Database(); | |
$reading_time = $db->get($postId); | |
if(!$reading_time) return; | |
// https://medium.com/write-better-wordpress-code/provide-overwritable-templates-from-your-plugin-c5205f8a3138 | |
$templates = new \PublicFunctionOrg\WordPress\Templates(); | |
include $templates->get_template_path("reading-time-template.php"); | |
} | |
function reading_time_get_content($post_id){ | |
ob_start(); | |
// https://gist.github.com/EdwardBock/fa659b67bcf4f568289d0c49c175f42b | |
reading_time_render($postId); | |
$content = ob_get_contents(); | |
ob_end_clean(); | |
return $content; | |
} |
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 | |
/** | |
* @var int $reading_time | |
*/ | |
echo "<p>Estimated reading time: $reading_time minutes</p>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment