WordPress.org

Support

Support » Themes and Templates » Automatically add “read more” button to main page

Automatically add “read more” button to main page

  • 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?

Viewing 1 replies (of 1 total)
  • hi

    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');

Viewing 1 replies (of 1 total)
  • The topic ‘Automatically add “read more” button to main page’ is closed to new replies.
Skip to toolbar