0

I'm using the_excerpt(); in blog.php file (post listing page) and it doesn't recognize <!--more--> if "Excerpt" field is empty and it grabs the beginning of the content as excerpt.

This issue is described here: http://codex.wordpress.org/Template_Tags/the_excerpt but I don't know why did WordPress disable <!--more--> for the excerpt (if excerpt field is empty and content is used as excerpt)?

Can i enable that back?

10
  • What precisely do you mean by "doesn't parse"? You cover how it works but how does it differ from what you expected and/or want to achieve?
    – Rarst
    Nov 10 '12 at 19:20
  • It displays content after <!--more--> tag and doesn't stop at it like it should.
    – Paul
    Nov 11 '12 at 9:31
  • That is not native behavior. Generated excerpt can't be longer than teaser (from start of post to more tag). Something interferes in your case but it's hard to guess what without more details.
    – Rarst
    Nov 11 '12 at 13:25
  • @Rarst I think nothing interferes - it's now very clear to me what happens and this is already resolved (see accepted answer to this question).
    – Paul
    Nov 11 '12 at 19:44
  • Well, the behavior you are describing is not correct, so something is wrong with it. Just wanted to comment on that.
    – Rarst
    Nov 11 '12 at 19:49
2

I do not know why the WordPress powers that be decided to do it the way they did but they don't consider the part before the <--more--> to be the same as the excerpt. Whether that makes sense or not is probably an irresolvable matter of perspective. I'd accept it and make do. The distinction actually adds flexibility to your content management so long as you are aware of what is happening. If you want to use the <--more--> just do this...

if ( !empty( $post->post_excerpt ) ) the_excerpt();
else the_content();

The code that parses the <--more--> is hard-coded into get_the_content so it isn't just a matter of removing/adding a filter, though certainly you could juggle filters, or create one, to make this work. That is a more complicated solution and is in my opinion not worth it.

2
  • If there is no pre-made excerpt, the_excerpt() triggers get_the_content('') via wp_trim_excerpt(). So your check is redundant, that happens already by default in core.
    – fuxia
    Nov 14 '12 at 17:47
  • @toscho, the output is not the same. If you use the_excerpt() and you have a post_excerpt things work as expected. If you do not have a post_excerpt then the_excerpt() will grab post content and will break on the <!--more--> if and only if the content before the more is short enough. If the content before the <!--more--> is too long-- longer than $excerpt_length-- then the_excerpt() will truncate the "more" content anyway. In order to guarantee that the <!--more--> is honored you have to use the_content(), not the_excerpt(). The switch above is not redundant.
    – s_ha_dum
    Nov 14 '12 at 18:20

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.