Support » Plugins » Working with get_the_excerpt() in plugin

  • I’m writing my first plugin and hit a wierd snag. I’m using get_the_excerpt(), which automatically uses the first 120 (I think) characters of the post if there isn’t a specified excerpt. However, when it does this, it doesn’t seem to go through the same set of filters as a specified excerpt would. Some of the characters are different and less URL-encoding friendly. Any ideas why or how to fix this?

    Hope this question makes sense. Rereading it’s a bit confusing. Thanks for any help you might be able to offer.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The reason is there are a number of filters (formatting functions) which run on the_excerpt() but do not hit get_the_excerpt(), wptexturize() being one example.

    You can work around this by passing it through the_excerpt filters:

    $excerpt = apply_filters('the_excerpt', get_the_excerpt());

    Thanks, but for some reason this doesn’t work for what I want to do. Here’s what I tried with your code:

    $ap_message = apply_filters('the_excerpt', get_the_excerpt());
    echo '<a href="message.php/message=' . urlencode($ap_message) . '">link</a>';

    With this, the urlencoding doesn’t seem to work completely. It doesn’t create apostrophes correctly and in generated (not specified) excerpts, double space comes out as the  character. I’m so confused 🙁

    I’m gonna keep playing with it, let me know if I’ve misinterpreted something. I really appreciate the help.

    Oh, and the following code works beautifully for specified excerpts but not for generated ones:

    $ap_message = get_the_excerpt();
    echo '<a href="message.php/message=' . urlencode($ap_message) . '">link</a>';

    Still can’t figure this out. Is there a way to manually apply the filters without using apply_filters()? That might be barking up the wrong tree anyway. At this point I’m worried I might have to generate my own excerpts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Working with get_the_excerpt() in plugin’ is closed to new replies.