-
Posted in : Readme
-
1.10 came out today and I was hoping to see that the issue with read-time page bloat was resolved. To remind you… the read-time javascript actually forces the page to load the graphics off of the posts it analyzes. Since this theme uses LARGE images as featured images, this can significantly increase the page size. For example, at last check it was adding 700k+ to each homepage view!
Here is how I resolved the issue, I hope you tweak it to your needs and implement this in a future version.
1. Remove the javascript in functions.php
wp_deregister_script( 'readingTime' );2. Add the following two functions to the functions.php. One is ALMOST an exact duplicate of your shortcode. I didn’t want to replace yours since this theme still hasn’t matured past the point of not getting tons of updates. The other functions is a short and simple function that calculates read time.
// Latest from blog
function my_latest_from_the_blog( $atts, $content = "" )
{
extract( shortcode_atts( array( 'items' => "",
'category_slug' => "" ), $atts ) );
$post_list = "";
$args = array( 'posts_per_page' => $items, 'category_name' => $category_slug );
$posts = get_posts( $args );
if ( $posts )
{
foreach ( $posts as $post )
{
setup_postdata( $post );$post_list .= 'ID ) . '">' . get_the_title( $post->ID ) . '' . my_read_time() . ' ' . __( 'read', 'read' ) . '';
}wp_reset_postdata();
}
$latest_from_the_blog = '' . $post_list . '';
return $latest_from_the_blog;
}
// Read Time
// Medium post on how to calculate http://smri.io/vz9n
function my_read_time() {
$avg_word_per_sec = 275/60;
ob_start();
the_content();
$content = ob_get_clean();
$word_count = sizeof(explode(" ", $content));
$img_count = substr_count(strtolower(get_the_content()),"img");
$time_in_min = round((( $word_count / $avg_word_per_sec ) + ( $img_count * 12 )) / 60);
if($time_in_min < 1) { $time_in_min = 1; }
return $time_in_min . " min";
}
add_shortcode( 'my_latest_from_the_blog', 'my_latest_from_the_blog' );
3. If you use the shortcake [latest_from_the_blog] on any page, simply replace it with [my_latest_from_the_blog items=“5”].
4. You will have to copy the post templates to your child theme and modify the templates. Where you see
Change it to
It looks like the forum murdered some of that. You can download it here.
http://smri.io/nbi7
You must be logged in and have valid license to reply to this topic.