Limit Words and Characters in content WordPress

Sangwan Pankaj Reply 21:22
add_filter('the_content', 'trim_content');

// This function use to modify you content functions
function trim_content($content){
  $word_limit =30;
  $words = explode(' ', $content);
  return implode(' ', array_slice($words, 0, $word_limit));
}


OR

add_filter('the_content', 'trim_content');

// This function use if  the content having more than 100 charaters it converts into excerpt format.
function trim_content($content)
{
    if(is_archive())
    {
       
// I'm getting the first 100 characters just to show an example you can change the value to get the words..
        $content = (strlen($content) <= 100)? $content : wp_html_excerpt($content, 100);
    }

    return $content;
}

Related Posts

Wordpress 1093705854106692938
Copyright by GhostPHP. Powered by Blogger.

Search

Recent Post

Popular Posts

Follow us