HTML in info box/excerpt

Home Forums MapPress Support HTML in info box/excerpt

Tagged: ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #18748
    jreyes
    Participant
    #18749
    Chris
    Keymaster

    Hi,

    I don’t think it’s changed, but MapPress calls the function wp_trim_words() to limit excerpts to 55 characters.  That function also strips out any HTML tags and characters.

    The wp_trim_words() function is also called in normal theme functions like the_excerpt().  It’s an involved process, this article has an explanation:

    https://www.satollo.net/how-the_excerpt-function-works-in-wordpress

    Anyway, if you want to force tags through, there’s a filter that allows you to determine what wp_trim_words() should return.  The filter’s last argument is the orginal text, so if you add the following to your theme’s functions.php file, it should return it unaltered.

    Note that this will affect all excerpts, including elsewhere in the blog.

    function mytrimwords($text, $num_words, $more, $original_text) {
    return $original_text;
    }
    add_filter('wp_trim_words', 'mytrimwords', 10,4);
    
    #18762
    jreyes
    Participant

    Thanks for your quick reply! I don’t think I quite have my head around this. Yes – the code you posted works perfect for all excerpts. I’m not quite seeing how to address this for only the map custom post type.

    I have tried modifying the ‘get_the_excerpt’ filter, but it appress the mappress excerpt is not responding to that filter.

    I found in mappress_poi where the function get_post_excerpt is using wp_trim_words.

    Do I have to filter that result somehow?

    #18763
    Chris
    Keymaster

    Sorry, I didn’t realize the change should be only for maps.

    It’s possible to do this using filter ‘mappress_post_query’ instead. That filter lets you modify the results of a mashup query before it’s displayed.

    However, I think it would make more sense to just add a new filter ‘mappress_poi_excerpt’ specifically for excerpts, since this issue comes up frequently – many themes & plugins modify the standard functionality.

    Could you use the contact form to send a login to your blog? I’d like to add the new ‘mappress_poi_excerpt’ filter directly to your plugin, and once it’s working for you, I’ll also include it in the next release.

    #18816
    jreyes
    Participant

    Hi Chris,

    I used the new filter to get the HTML to show, however my shortcode are being executed. (I realized they were not executed anyway with the filter returning $excerpt).

    Is there a way to have the excerpt with HTML and shortcodes being executed?

    #18817
    Chris
    Keymaster

    Hi,

    I’m not clear on whether you do or do not want the shortcodes, but if you don’t want them, you can call strip_shortcodes() on the text. If you do want them executed, use do_shortcode() on it.

    I hope that’s enough info… Also, please be aware that not all shortcodes will work in a popup. For example, some need to load their own JavaScripts, and they won’t realized it’s necessary if the shortcode is embedded in a popup.

    #18818
    jreyes
    Participant

    Thanks! I tried do_shortcode with a very basic shortcode and it did work, so must be my shortcodes.

    For anyone else that might be reading this ticket – this is the code to put in your functions.php to return your excerpt with the html in your poi:

    function rawpoi($excerpt, $raw) {
    return $raw;
    }
    add_filter(‘mappress_poi_excerpt’, ‘rawpoi’, 10, 2);

     

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.