Skip to main content
added 194 characters in body
Source Link
Michelle
  • 3.5k
  • 4
  • 26
  • 34

I believe that's telling you that $post (in $post->ID) is undefined. Try this instead:

function sh_reading_time() {
    $content = get_post_field( 'post_content', get_the_ID() );
    $word_count = str_word_count( strip_tags( $content ) ); 
    $readingtime = ceil($word_count / 200);
    
    if ($readingtime == 1) {
      $timer = " minute";
    } else {
      $timer = " minutes";
    }
    $totalreadingtime = $readingtime . $timer;

    return $readingtime;$totalreadingtime ;
}

I believe that's telling you that $post (in $post->ID) is undefined. Try this instead:

function sh_reading_time() {
    $content = get_post_field( 'post_content', get_the_ID() );
    $word_count = str_word_count( strip_tags( $content ) ); 
    $readingtime = ceil($word_count / 200);

    return $readingtime;
}

I believe that's telling you that $post (in $post->ID) is undefined. Try this instead:

function sh_reading_time() {
    $content = get_post_field( 'post_content', get_the_ID() );
    $word_count = str_word_count( strip_tags( $content ) ); 
    $readingtime = ceil($word_count / 200);
    
    if ($readingtime == 1) {
      $timer = " minute";
    } else {
      $timer = " minutes";
    }
    $totalreadingtime = $readingtime . $timer;

    return $totalreadingtime ;
}
Source Link
Michelle
  • 3.5k
  • 4
  • 26
  • 34

I believe that's telling you that $post (in $post->ID) is undefined. Try this instead:

function sh_reading_time() {
    $content = get_post_field( 'post_content', get_the_ID() );
    $word_count = str_word_count( strip_tags( $content ) ); 
    $readingtime = ceil($word_count / 200);

    return $readingtime;
}