I’m not sure I understand your post, but this function, placed in your functions.php file, will change the “Read More” tag:
add_filter( 'the_content_more_link', 'modify_read_more_link' );
function modify_read_more_link() {
return '<a class="more-link" href="' . get_permalink() . '">Your Read More Link Text</a>';
}
(Taken from the Codex.)
Hi Peninah,
I currently have that in my functions.php however this will replace all instances of the read more tag with the texteam inside the function. If you supply the generic read more tag with attributes it will change the text of the read more link.
So ‘<!–more–>’ would display the wp default text of (more…) and ‘<!–more Read This –>’ would display Read This. I want to set the default text to something other than (more…)
This would allow me to keep the functionality of the original read more tag which allows flexibility that I could need.
The issue here is that WordPress doesn’t have a specific function to read the <!--more--> tag; instead, WP parses out the tag as part of get_the_content(). There are no filters available to intercept it, either; the_content_more_link and the_content both run after WP has parsed out the tag, so a function hooked to either filter can’t see that the tag was there.
You can set the contents of the “More” link by passing an argument to the_content(), so one thing that might work is to set up a custom field using something like ACF and passing the contents of that field to the_content().
The only other way I can think of would be to copy the contents of get_the_content() to your own custom function and experiment with the preg_match() lines.
I found the answer to my problem.
Inside my function.php file I needed
function my_the_post_action($post_object) {
//Set Default Link Text
$link_text = 'Default';
$post = $post_object->post->post_content;
if (preg_match('<!--more ' . '(.*?)' . '--> ', $post, $matches)) {
//Returns Link Text String If Found
return $matches[1];
}else{
return $link_text;
}
}
add_action('loop_start', 'my_the_post_action');
Then inside my template file I.E. index.php all I need to for my post content is
the_content(my_the_post_action($post_object))
This may not be the most elegant way of handling this, but it’s the only way I could find to get the post content prior to the more link being created. This will pass the desired default text into the_content() to change the read more link dynamically while allowing me to set a custom default more link. This will save time on creating posts instead of having to remember to say <–more {Something Custom} –>
Or a more elegant way to do so. It’s mixed in with a function to wrap the more link in a div.
function wrap_readmore($more_link)
{
//Check if link contains default (more...), if it does replace with Read More
if(preg_match('(more…)', $more_link)){
$more_link = str_replace('(more…)', 'Read More', $more_link);
}
return '<div class="small-12 columns text-center">'.$more_link.'</div>';
}
add_filter('the_content_more_link', 'wrap_readmore');
Thanks for posting your solution!
Hi all… well this “Read More” tag was driving me crazy :-Z
I searched everywhere for a solution and I could’t find any for the latest WordPress version. So I had to dig and dig through a lot of PHP files, till I finally found it!
Probably this is not the most recommended/fancy solution, but it worked for me so I want to share it.
Look for this file initialize.php
You can find it in this route
/wp-content/themes/your-themes-name/inc
Search for this line __( ‘Read More’, ‘your-themes-name’ )
And replace the text ‘Read More’ with whatever you want.
Also you can change the text for the Search widget…
placeholder=”‘.__( ‘Search here..’, ‘your-themes-name’ )
And replace the text ‘Search here’ with whatever you want.
The theme that I am using is the Maskitto Light.
Hope this helps!