How to display More tag and trimmed Excerpt

I was working on a wordpress blog posts page, i faced a tricky situation. Many blog users dont like fixed trimmed length content and they want to display their own trimmed versions, using <!–more–> . If the post has <!–more–> tag, display it or if no more tag is present, just display the_excerpt() a trimmed one.

How do you do it? They key here is to first compare and use the_content() which displays until more tag is found.  The excerpt function only displays the trimmed version and of course they both can co-exist.

<?php
     if( strpos( get_the_content(), 'more-link' ) === false ) {
                    the_excerpt();
                }
                else {
                    the_content('Continue Reading &raquo;');
                }     
?>

Finally, to customize read more to display for excerpts, paste this code in your functions.php (in your theme)

add_filter('excerpt_more', 'theme_excerpt_remove');

function theme_excerpt_remove( $more ) {
    return ' <p><a href="'. get_permalink( get_the_ID() ) . '">Continue Reading &raquo;</a></p>';
}

Now you will see the Continue reading with appear as a link to your blog post list. Keep in mind that more tag has no effect on singlepost.php and wont work on page.php.

Author: Prabhu, Hungary.

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz