[Resolved] Limit number of words in posts when query specific tag/category

Home Forums Support [Resolved] Limit number of words in posts when query specific tag/category

Home Forums Support Limit number of words in posts when query specific tag/category

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1657498
    Joyce

    Hi Team,

    I’d like to restrict number of words in post when I see the post list for specific tag/category
    e.g. http://www.abc.com/tag/tag1, http://www.abc.com/category/catatory1

    thanks,
    Joyce

    #1657936
    David
    Staff
    Customer Support

    Hi there,

    you can use a filter like this:

    add_filter( 'excerpt_length', function( $length ) {
        $categories = array(
            'cat-one',
            'cat-two',
            'cat-three',
        );
        $tags = array(
            'tag-one',
            'tag-two',
            'tag-three',
        );
    
        if ( is_category( $categories )  || is_tag( $tags ) ) {
            $length = 25;
        }
    
        return $length;
    }, 200 );
    #1661069
    Joyce

    thanks David

    #1661475
    David
    Staff
    Customer Support

    You’re welcome

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.