'Allow inner HTML tags in product short description on shop page

I am displaying the product short description on my front page. My problem is, that the html-tags, for example lists, are not displayed. The text comes without any html. On my single-product page everything is displayed fine. Is there a way to keep these tags?



Solution 1:[1]

Wordpress does not show by default HTML in excerpt. We need to create a function that filters the content in a different way Wordpress does it nativelly and we replace the filter, using ours instead of Wordpress one.

This is the solution

function lt_html_excerpt($text) { // Fakes an excerpt if needed
    global $post;
    if ( '' == $text ) {
        $text = get_the_content('');
        $text = apply_filters('the_content', $text);
        $text = str_replace('\]\]\>', ']]>', $text);
        /*just add all the tags you want to appear in the excerpt --
        be sure there are no white spaces in the string of allowed tags */
        $text = strip_tags($text,'<p><br><b><a><em><strong>');
        /* you can also change the length of the excerpt here, if you want */
        $excerpt_length = 55; 
        $words = explode(' ', $text, $excerpt_length + 1);
        if (count($words)> $excerpt_length) {
            array_pop($words);
            array_push($words, '[...]');
            $text = implode(' ', $words);
        }
    }
    return $text;
}

Then, we remove the default filter and add the one you created with the function above:

/* remove the default filter */
remove_filter('get_the_excerpt', 'wp_trim_excerpt');

/* now, add your own filter */
add_filter('get_the_excerpt', 'lt_html_excerpt');

The solution was found here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduhud