Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit wordpress.stackexchange
scroll top