• Hello! I really need your help!
    I created a single record template. In this template, I have a field in which I derive the approximate time for reading the article using a shortcode.

    Here is the php code for counting characters:

    function reading_time() {
      $content = get_post_field( 'post_content', $post->ID );
      $word_count = str_word_count( strip_tags( $content ) );
      $readingtime = ceil($word_count / 1);
      if ($readingtime == 1) {
        $timer = " минуту";
      } elseif ($readingtime == 2 || $readingtime == 3 || $readingtime == 4) {
        $timer = " минуты";
      } else {
        $timer = " минут";
      }
      $totalreadingtime = 'Время чтения: ' . $readingtime . $timer;
      return $totalreadingtime;
    }
    add_shortcode( 'readingtimes', 'reading_time');

    The problem is that he incorrectly counts the number of characters, shows that I have 13 characters in total (I set the division by 1 specifically to verify this).

    Perhaps the fact is that I have several text editors, a list with icons, etc.

    How to make it work?

    I would be very grateful for the help!

  • The topic ‘I can not count the number of characters’ is closed to new replies.