Shortcodes in excerpts
-
For the sake of this post I will assume a shortcode
[foo]
which always renders tobar
, but this applies to all shortcodes, including the built-ins.It seems that WordPress doesn’t render shortcodes in excerpts, but WooCommerce, which uses excerpts for short descriptions, does. Take, for example, a WooCommerce product with a short description of
[foo]
. If you visit the product page, this displays asbar
. However, if you search forbar
you get no results, but if you search forfoo
then you get that product, with the shortcode source code in the search result excerpt.I can add the line
add_filter('get_the_excerpt', 'do_shortcode');
to functions.php, and this causes the search result excerpt to showbar
. However, a search forbar
still returns no results, a search forfoo
still returns the product, and ifbar
were instead block-level content like an unordered list, it would not be made to display inline like normal search result excerpts are.Since I’m using the Reusable Blocks Extended plugin to put much of my product text behind shortcodes for the sake of reusability, this is totally crippling search for me. Half of my content isn’t indexed, and search results often contain source code.
Is this a WordPress bug, or a WooCommerce bug, or are WordPress and WooCommerce in disagreement?
If they’re not going to reconcile, then is there a place I can hook in do_shortcode so that it’s rendered before indexing and before the HTML stripping of search result excerpts?
- The topic ‘Shortcodes in excerpts’ is closed to new replies.