Support » Plugins » Hacks » Forcing get_the_excerpt() to output “automatic” excerpt

  • Hello guys,

    I would like to be able to have get_the_excerpt() returns an automated excerpt, even if the user has entered a manual excerpt.

    I searched online but haven’t been able to find a solution to this…

    Basically I would like to be able to use both auto excerpt and manual excerpt…

    Do you have idea or tips on how to do that ?

    Thanks,

    Cheers,

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    There’s two kinds of manual excerpt, the inserted “more” comment tag and the separate excerpt post field. Then you say you want automatic, which is the other excerpt type unless you count full content as an option. But then you say you want to use both automatic and manual.

    When you use various combinations of manual and auto combined with the_content() and the_excerpt() plus the length of the post content, you get all sorts of permutations of behavior. So I’m not sure what you’re really after, but I think I can help anyway.

    By default, wp_trim_excerpt() is hooked into wp_trim_excerpt() as a callback. To reduce complications, I suggest you remove this hook. Then the default for get_the_excerpt() will return whatever is in the posts’s excerpt field, and only that. Very simple. Then hook your own callback into “get_the_excerpt” filter and return whatever it is that you want to be displayed. Because this is in the loop and the current $post object is passed as the second parameter, you can get whatever data you want and assemble it into the desired HTML, then return the assembled output. You can implement all manner of convoluted (or simple) logic you want this way.

    Moderator bcworkz

    (@bcworkz)

    By default, wp_trim_excerpt() is hooked into wp_trim_excerpt() as a callback.

    WTF? Arrgh! Copy/paste error, sorry. By default, wp_trim_excerpt() is hooked into the “get_the_excerpt” filter as a callback.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Forcing get_the_excerpt() to output “automatic” excerpt’ is closed to new replies.