Support » Developing with WordPress » how to display a video by using wp_trim_words in front end ?

  • I want to trim the words of post content that’s why I used wp_trim words. But when I include a video in post content then it shows the video link and trimmed text in the frontend. I want to show the video not the video link trimmed text in the frontend. To solve the problem what can be used instead of wp_trim_words?

    here is my code below

    <div class="post-body">
     <?php echo wp_trim_words( get_the_content(), 25, ''); ?>
     <p>
      <a>" class="btn btn-color btn- 
      sm">Read More</a>
    </p>
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Trim words strips all HTML tags so it can more accurately count the words. There’s no reasonable mechanism to put them back afterwards that would work in all cases. You would need to take your own measures to preserve the video embed.

    One approach is to extract out the video embed, keeping it in a variable for later use. Replace the embed with an innocuous placeholder like “%viddy%”. After trimming, replace the placeholder with the embed code saved earlier.

Viewing 1 replies (of 1 total)
  • The topic ‘how to display a video by using wp_trim_words in front end ?’ is closed to new replies.