0

I want to show the post content until the more tag, or if there's no more tag than just first n words. Something really basic, right? Obviously I need to use get_the_excerpt function. But the problem is that this function is behaving strangely. It adds a suffix to the end, that nobody wants. And you can't remove it!

You could in the pas do this

But this no longer works, because Wordpress decided to give us even more bad time with this by changing [...] to something like […]

Now you can't even str_replace or rtrim that […]. Trust me I tried.

The solution from here works, but this only cuts text after n words. It ignores the more tag.

Another way would be to use get_the_content, but that just shows the full post content even if I select Summary in the Settings -> Reading.

So please, what am I missing here?

1

The excerpt has a maximum lenght of 55 words, so even if you try to cut your text at say 70 words, the_excerpt() will ignore that and only show 55 words.

To remove[...] from the read more tag, simply find the_content() and replace it with the_content('',FALSE,'');. You can also use the_content('Read more...'); to display a text after the read more tag, in this case Read more....

If you need to remove [...] from the excerpt, you can do this in your functions.php

function new_excerpt_more($more) {
       global $post;
    return '';
}
add_filter('excerpt_more', 'new_excerpt_more');

You can also add a custom text or link inside the '' if you need something else to dispay

  • Tried the_content('Read more...') and the_content('',FALSE,''). They both show the entire content. So another mistery. :( But the snippet you provided works...thank you! So the "excerpt_more" is the keyword I was supposed to search for.. – user568021 Mar 28 '14 at 9:52
  • Just glad I could be of help. Enjoy – Pieter Goosen Mar 28 '14 at 10:09

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.