How to set a Read More Link on Blog Archive page

Generally, the excerpt function allows you to show your post’s first “55” words in the archive pages (categories and tags) and the homepage.

Post Excerptt

So what if you want to show the Read More button for all of the posts. Well, to do so, you can inject this below code to your theme/child-theme’s functions.php file.

//Read More Button For Excerpt on the blog post archive page or homepage
function excerpt_read_more_link( $output ) {
    global $post;
    return $output . ' <a href="' . get_permalink( $post->ID ) . '" class="ReadMore" title="Read More">Read More</a>';
}
add_filter( 'the_excerpt', 'excerpt_read_more_link' );

You can also manipulate the ReadMore class for custom CSS styling.

BONUS

Apart from this, what if you want to show the excerpt words with more than “55” words!

There is two way one is a manual process. Like- edit the associated post and insert your excerpt manually on the excerpt meta-box (like below). Yea, this is a quick solution.

How to set a Read More Link on Blog Archive page 1

But imagine, you have hundreds or more articles published on your site & you want a quick solution for that. Isn’t it a bummer to edit all existing posts to update the excerpt?

Custom function Method

To avoid that such a situation, luckily, WordPress has a built-in filter named excerpt_length that will allow changing the default length of your excerpts from your theme/child-theme functions.php

/* Increase the default post excerpt length */
add_filter( 'excerpt_length', function($length) {
    return 35;
} );
How to set a Read More Link on Blog Archive page 2

Tie-up

Oh, How lazy I’m! This is all for now. See you soon with another tip.

Cheers!

MM Aurangajeb
MM Aurangajeb

Spreading Happiness. Support Engineer, WordPress Enthusiast, Blogger.

Articles: 18

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.