I’m trying to add a “Time to Read” just above every post and I can’t, for the life of me, get it to work.
I’ve already created the folder under Newsmag’s “js” folder and the readingTime.js file is in there. I also added the necessary “script” code into “footer.php”.
Where I’m stumbling is that I can’t figure out how I need to change the code and where to put it so that “Time to Read: XX (XX Words)” appears in a line just above the body of every post.
Here’s the code I’m working with:
(Added to “functions.php”)
function readingtime_posts() {
if (is_single() && wp_script_is('readingtimejs','done')) {
?><script type="text/javascript">jQuery(document).ready(function($) {
$('.td-post-content').readingTime({
readingTimeTarget: '.reading-eta',
wordCountTarget: '.word-count',
wordsPerMinute: 180,
round: true,
prependTimeString: 'Time to Read: '
});
});</script><?php
}}
add_action('wp_footer','readingtime_posts',100);
(Added into “loop-single.php”)
<?php if (is_single()) {
echo '<div style="clear:both;"><span class="reading-eta"></span> (<span class="word-count"></span> Words)</div>';
}
?>
Here’s a screenshot of where the loop-single.php code is located: https://s10.postimg.org/raid1n9vd/Screen_Shot_2016_09_12_at_7_09_16_PM.png
Please tell me what I’m doing wrong!!!
@neotrope That worked! The line is there, but the problem is that it’s not running the actual script. It just says “( Words)” and leaves out all the stuff from the function. I feel like that means the code in the function.php isn’t right maybe.
HI
We didn’t made any tests and I can’t provide an accurate answer in this regard. However checking your post I’ve found a js error in browser’s console: http://screencast.com/t/Eslaboa0Do I am not sure if this error is related with the js file that you created but it may affect how the plugin works.
If you still can’t manage to solve this issue and you really need to use this plugin my advice is to look for someone who can help you with implementation or hire a freelancer to do it for you as we can’t offer customization services at the moment.
Thanks!
