1

Is there a way to use Wordpress' read more text?

As you can customize the read more text, it would be nice to be able to reuse that text elsewhere instead of hard coding it.

My goal is to use the read more text without having to use the_content() or the_excerpt().

Is there a function like the_read_more_link() which can get the link and the text, or just the text?

  • 1
    Hello Bjørnar Hagen, and welcome to the site. I would like to ask for clarification, please. Do you mean that (1) you want to set the read more text in one place and have it applied to all content and excerpt read more links as the default text? Or, (2) do you mean that you want to have a specific read more text snippet to use with other tags beside the_content and the_excerpt? If it is the latter (#2), where or with what template tag do you want to apply the read more text? – jsmod Apr 6 '19 at 19:43
  • 1
    Thanks for the warm welcome jsmod! My question is more like number 2. I want to use it anywhere within the loop. I guess I'm asking if there is a template tag, or something similar for getting the default "read more", or the custom one that has been set with the the_content_more_link filter. – Bjørnar Hagen Apr 6 '19 at 19:57
  • Ok, so inside the loop usually the excerpt or the content would make use of a read more text as they need something like that. Those two can be customized with the excerpt_more and the_content_more_link filters. But I can't think of a specific case where a "read more" link would be needed with other tags anywhere in the loop. Can you give a specific example? – jsmod Apr 9 '19 at 23:43
  • However, if you just want a reusable bit of text that can be used in the loop and other places repeatedly you might consider php includes to call that bit of text when you need it. – jsmod Apr 9 '19 at 23:46
0

Sure, this is possible. The starting point is a filter like this, which I understand you are currently using in some form:

add_filter ('excerpt_more','wpse333680_more_text',10,1);
function wpse333680_more_text ($more-text) {
  return 'Everything you always wanted to know about this >>';
  }

The function you use for the filter can easily be reused elsewhere. You could echo it anywhere in a theme or plugin (or even in a shortcode):

echo wpse333680_more_text();

If this is not enough you could modify the filter to include conditions so it reacts differently to various situations:

add_filter ('excerpt_more','wpse333680_more_text2',10,1);
function wpse333680_more_text2 ($more-text) {
  if (condition)
    return 'Everything you always wanted to know about this >>';
  else
    return $more-text . 'Everything you always wanted to know about this >>';
  }

Depending on the condition this would either replace the $more-text completely or concatenate the string to it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.