Shortcode in search result

I added the following code to my functions.php file in my child theme to show the short description on WooCommerce index pages, but on search it shows the shortcode instead of the content. I saw some other posts about this but none of the ones I saw were the same situation as mine. How do i remove the shortcode?

// Add Short Description WooCommerce Product/Category Loop
function woocommerce_after_shop_loop_item_title_short_description() {
	global $product;
	if ( ! $product->post->post_excerpt ) return;
	?>
	<div itemprop="description">
		<?php echo apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ) ?>
	</div>
	<?php
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5);

Website is https://test.iguchibear.com

Search for Special Wheel and you will see what I mean.

Thanks, Todd

Hello Todd,

Thanks for writing in!

Your code displays the excerpt with plain text. You need to render the shortcodes as well. Please have your code updated and use this code instead:

// Add Short Description WooCommerce Product/Category Loop
function woocommerce_after_shop_loop_item_title_short_description() {
	global $product;
	if ( ! $product->post->post_excerpt ) return;
	?>
	<div itemprop="description">
		<?php echo apply_filters( 'woocommerce_short_description', do_shortcode($product->post->post_excerpt) ) ?>
	</div>
	<?php
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5);

We would love to know if this has worked for you. Thank you.

That didn’t work. I am still seeing the button shortcode in the search results. I cleared cache and cookies.

Hello Todd,

Please use this code instead:

// Add Short Description WooCommerce Product/Category Loop
function woocommerce_after_shop_loop_item_title_short_description() {
  global $product;
  if ( ! $product->post->post_excerpt ) return;
  ?>
  <div itemprop="description">
    <?php echo do_shortcode( apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ) ); ?>
  </div>
  <?php
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5);

Hope this helps.

Nope…still didn’t work. The image appears fine but the text below is still showing the button shortcode.

Hello Todd,

Please provide us access to your site so that we can check your settings and your child theme’s template overrides. Please create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

To know how to create a secure note, please check this out: https://theme.co/apex/forum/t/how-to-get-support/288

Thank you in advance.

Information requested sent in secure note.

Hey Todd,

I didn’t do anything but it looks like you already have achieved what you need.

Is this happening on a specific page? If so, please give us the URL.

Thanks.

Did you conduct a search? It’s happening in search results. Everywhere else is fine.

https://test.iguchibear.com/?s=special+wheel

Hi Todd,

I checked the website and tested a few cases, I added a Global Block and used that shortcode and it is not working, Then I used another shortcode which is not part of our theme or builder and it did not work either.

This seems to be the lack of support for shortcodes in the Short Description feature of Woocommerce in search pages.

Please kindly consider that this is a customization request and is outside of our support scope, but I did a google search which might help you find a solution to force the case to support shortcodes.

Thank you for your understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.