Automatically add "read more" button to main page (2 posts)

  1. wowconomics
    Posted 5 years ago #

    I am looking to truncate my posts on my main page of http://www.sweetredwine.net. I want to only show about 5-10 lines and have a "read more" button to read the rest of the article. Is there a easy way I can add code to my template to automate shortening the articles on my site?

  2. stvwlf
    Posted 5 years ago #


    1) In your homepage template, change the_content( ..... ) to
    the _excerpt() - this displays the first 55 words of the post followed by [...].

    2) in your theme's functions.php file, add this code, which replaces the default WP excerpt ending of [...] with a read more link:

    function excerpt_ellipse($text) {  // custom 'read more' link
       return str_replace(' [...]', '... &nbsp;<a href="'.get_permalink().'">Read more</a>', $text); }
    add_filter('the_excerpt', 'excerpt_ellipse');

Topic Closed

This topic has been closed to new replies.

About this Topic