WordPress.org

Ready to get started?Download WordPress

Forums

Exerpt to allow html tags, eg <a>? Non-core hack (3 posts)

  1. DazVision
    Member
    Posted 3 years ago #

    Hi,

    Has anyone successfully written code to allow specific tags within an excerpt? Eg, my client wishes for links (<a href... tags) to be written when the_excerpt() is printed to the page. Currently, the excerpt strips all tags.

    I do not wish to use a plugin (which is dependent on a version keeping up to date with WP core updates) and I don't want to write code that re-writes the core. I was hoping to use a filter, but that doesn't seem possible as I couldn't find a filter that hooks onto the excerpt.

    Any help would be greatly appreciated.
    Cheers.

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    a possible hook is 'get_the_excerpt':

    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wp_trim_excerpt_new');
    
    function wp_trim_excerpt_new($text) {
    /*your function here*/
    }
  3. DazVision
    Member
    Posted 3 years ago #

    Cheers alchymyth,

    I had already used that hook and had copied the code from the wp-includes/formatting.php Then, as you suggested, I wrote a function to replace it: the only thing that I needed to change was the strip_tags function.

    However, I'm trying to find a option other than this. I noticed that the function wp_trim_excerpt hasn't changed since 1.5, so that's good news, but in the event that it does change in the future, I can't guarantee it will work.

    Maybe it's not even an option yet but it would be really cool to hook into 'wp_excerpt_tags' or something like that.

Topic Closed

This topic has been closed to new replies.

About this Topic