Jump to content
Sign in to follow this  

How to Limit Synopsis the_content Words

Recommended Posts

You use the_content function in almost every page of your dooplay theme. For instance you use in peliculas.php, series.php file and  it will echo all the content for one post or page. But you don’t want to show all content. Maybe only 80 words. Here how you can limit the_content

Using Custom Function

This method is going to be the best and most flexible way to limit the_content words length. Write the following custom function in your functions.php file.

function dooplay_content($limit){
  $content = explode(' ', get_the_content(), $limit);

  if (count($content)>=$limit){
       $content = implode(" ",$content).'...';
  } else {
    $content = implode(" ",$content);
  $content = preg_replace('/\[.+\]/','', $content);
  $content = apply_filters('the_content', $content); 
  $content = str_replace(']]>', ']]>', $content);
  return $content;

Use the custom function instead of the_content. For example:

<?php echo dooplay_content(80); ?>


Edited by Babaman

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Who's Online   0 Members, 0 Anonymous, 4 Guests (See full list)

    There are no registered users currently online

  • Create New...