QUICK TIP - 2 easy ways to customise “Read more” – GeneratePress theme

- 1. QUICK TIP - Most Useful .htaccess Tricks for WordPress
- 2. QUICK TIP - How to Join and Earn From Brave Ads
2 easy ways to customise “Read more” – Activating Read More with Custom Excerpt is available for the best the fastest theme in WordPress theme market. Normally, the theme supports this feature depends on each design; however, we can customise it by adding function code below. We can use many ways to implement the code below such as using snippet, create plugin and add a child theme.
By default, WordPress skips all the excerpt_length
and excerpt_more
filters when the custom excerpt is used.
On the other hand, If you would like to use the read more links or read more buttons with custom excerpt. Besides, there are some articles that may help you find your expected answer.
Install code snippet plugin
Using Code Snippets is the best way to do this for beginners who are the first time using WP or never use it before. Therefore, this tutorial will focus on this way or you can view different ways to add PHP code in here.
Code Snippets is a WordPress plugin will help us to add PHP code into our website. It is so easy to use and install. Furthermore, we can easy backup restore or remove without any negative effects to the main website. You can activate and deactivate certain snippets, and even adds notes about what they do. It even has better error handling to avoid the PHP error.
To install it, in WP dashboard, simply go to Plugins > Add New and search for Code Snippets.
You use the two functions below depending on your situation.
If your theme shows “read more” as button and you want to change it to text, you will use “read more text“.
2 easy ways to customise “Read more”
Create “Read more text”
This section will show you how to create “Read more text” function and activating it in the world fastest theme Generate Press(GP). Thus, the code below will help you to solve this task for just copy & paste.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() ) { $output = sprintf( '%1$s <a href="%2$s">%3$s</a>', $excerpt, get_permalink(), __( 'Read more', 'generatepress' ) ); } return $output; } |
If your theme shows “read more” as text and you want to change it to button, you will use “read more button” below.
Read more button
1 2 3 4 5 6 7 8 9 10 |
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() ) { $output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>', $excerpt, get_permalink(), __( 'Read more', 'generatepress' ) ); } return $output; } |
Activate / Deactivate “read more” text / button in CODE SNIPPET
From dashboard, Snippets > All Snippets > “readmore_text” or “readmore_button” > activate/deactivate. This function is very useful because you can activate the function when you need. In contrast, if you do not need or temporary, you can go ahead easily with deactivate function on Code Snippet.
Final words
Hooray, this tutorial has already shown you how to customise the text on the button “read more” in a few easy steps. Furthermore, there are some articles that you may like it as below. We will support you to create a good website on the power, fastest and best theme – GP.