Limiting content in a post preview in front or blog page


I noticed the discussion using an excerpt to limit the post preview in the front or blog page. Here

What is the code to limit the content by words or characters in a post preview?

Thank you!

Hey Paal do this

add_filter( 'the_content', 'hyperindian_modify_post_content' );

function hyperindian_modify_post_content( $content ) {

    // Stop here if we are on a single view.
    if ( is_singular() )
        return $content;

    // Return the excerpt() if it exists other truncate.
    if ( has_excerpt() )
        $content = '<p>' . get_the_excerpt() . '</p>';
        $content = '<p>' . wp_trim_words( get_the_content(), 40, '...' ) . '</p>';

    // Return content and readmore.
    return $content . '<p>' . beans_post_more_link() . '</p>';


change the 40 on wp_trim_words

Awesome! Thank you very much for posting it Anupam even if I happen to miss it in the excerpt thread!

Hey paal

I'm glad that you found your answar.

Happy coding.

Write a reply

Login or register to write a reply, it's free!