0

Currenctly I have the post titles that are being limited by a wp_trim_words. Here is the code below.

    // Filtering character limit on post titles. 
    add_filter( 'the_title', 'wpse_75691_trim_words' );

    function wpse_75691_trim_words( $title )
    {
    // limit to ten words
    return wp_trim_words( $title, 10, '' ) . ' ...';
    }

The problem I'm running into is that now if I click that post title and it redirects me to the single page, the title does not go back to the original post title which was longer than 10 words.

Can someone give me some direction here? Pretty new to WP. Thanks!

0

WordPress has a is_single() function to check for this very condition inside the loop.

function wpse_75691_trim_words( $title ) {

    if( is_single() ) {
        return $title;
    }

    return wp_trim_words( $title, 10, '' ) . ' ...';
}

There is a fairly robust list of conditional tags in the Codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.