• For the sake of this post I will assume a shortcode [foo] which always renders to bar, 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 as bar. However, if you search for bar you get no results, but if you search for foo 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 show bar. However, a search for bar still returns no results, a search for foo still returns the product, and if bar 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @twhb

    I can’t speak to WooCommerce, as am not familiar with it, but shortcodes not rendering in WordPress search is a known limitation, unfortunately.

    The default search functionality in WordPress is quite naive and will only perform a simple database LIKE lookup.

    Often a workaround is to embed a third party search service (Google, Bing, etc.) which will index the website as it appears to end users.

    There are also plugins which add more advanced search to WordPress using e.g. Elasticsearch.

    Thread Starter twhb

    (@twhb)

    Thanks for the reply. I usually already use Relevanssi, so I’ll submit a feature request there too.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcodes in excerpts’ is closed to new replies.