Support » Plugins » Call to get_the_excerpt() on an excerpt-less post invokes the_content

  • Me thinks this should not be :). If a post doesn’t have an excerpt, get_the_excerpt() shouldn’t invoke the filter for the_content.

    E.g., if you have Alex King’s Share This plugin installed, get_the_excerpt() will return “Share This” on posts without excerpt.

Viewing 1 replies (of 1 total)
  • No, this is intended behavior. Calling get_the_excerpt() when there is not one will cause WordPress to fake it. It gets the content and then cuts out everything but the first 55 words of it, adds a […] to it, and returns that.

    the_content filter gets applied to the content before it trims off the end. It has to do this, because the raw content may contain things that control formatting or replacement of words and such and you don’t want those to be bypassed just because you’re getting an excerpt.

    This is why it’s generally a bad idea for plugins (including Share This) to use the_content filter to add things to display with the post but which are not part of it. Yes, a lot of plugins do it, because it’s easy. That doesn’t make it the correct thing to do.

    If you don’t want it to fake the excerpt, do this before your get_the_excerpt() call:
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');

    Make sure to do an add_filter if you need that behavior back afterwards.

Viewing 1 replies (of 1 total)
  • The topic ‘Call to get_the_excerpt() on an excerpt-less post invokes the_content’ is closed to new replies.