Excerpts in WordPress are a great way to preview a post or page without displaying the entire content. By default, WordPress automatically generates an excerpt with a “Read More” link at the end. You can easily change this link to suit your needs. In this article, we will show you how to change the “Read More” text using a code snippet.
The code snippet we will use is a WordPress filter, specifically the “excerpt_more” filter. Filters in WordPress allow you to modify or manipulate data in WordPress, such as post content, post titles, and in this case, excerpt more text.
Here is the code snippet that you can add to your WordPress site:
add_filter('excerpt_more', 'custom_excerpt_more');
function custom_excerpt_more($more)
{
return '...';
}
This code does two things:
- Adds a filter to the “excerpt_more” with the function name “custom_excerpt_more”.
- Defines the function “custom_excerpt_more”, which takes one argument, “$more”. The function returns “…”, which is the new excerpt of more text.
Once you have added this code to your WordPress site, the excerpt more text for all posts and page previews will be “…”. You can change the value of “…” to any text you want, depending on how you want your excerpts to appear.
In conclusion, customizing the excerpt more text in WordPress is a simple and effective way to control the appearance of your post and page previews. Using the “excerpt_more” filter and a code snippet, you can change the excerpt-more […] text to any text you want, making it a powerful tool for customizing your WordPress site.