• 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • 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*/
    }
    Thread Starter DazVision

    (@dazvision)

    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exerpt to allow html tags, eg <a>? Non-core hack’ is closed to new replies.