Skip Navigation

[Resolved] How to keep formatting from the short product description field

This thread is resolved. Here is a description of the problem and solution.

Problem:
The customer asked how to keep the HTML formatting in content coming from WooCommerce's short description field.

Solution:
Guided that WooCommerce uses WordPress post excerpts for this field and shared a custom shortcode snippet to get the excerpt.

Relevant Documentation:
n/a

This support ticket is created 2 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by tommyJ-3 2 years, 10 months ago.

Assisted by: Waqar.

Author
Posts
#2304847

In the product pages I need to show the content from the short description field (which is a normal WYSIWYG field, same as for the long description). The short description typically has a UL list and some standard formatting in my case.

I was very surprised to see that all html tags are stripped from this short description field.

One workaround would be to add an extra WYSIWYG product field named "short description 2" and link that field to a paragraph field in the template. I have tested this and it works. BUT it's confusing to have 2 "short description" fields. Also lots of work to move content from one field to another, when there are hundreds of products.

So can you supply me with another solution that does not strip formatting and that works with the default "short description" field?

I have looked at previous questions about the same thing, but these seem to be very old and involve menus that I cannot find in my version of Toolset (Views -> Compatibility for example).

#2304877

Hi,

Thank you for contacting us and I'd be happy to assist.

Based on what you've shared, I understand that you're using the "Product short description" field that is offered by the WooCommerce plugin in the products post type.

If that is correct, WooCommerce stores the content of that field as the post's excerpt field. To show its content, keeping the HTML formatting, you can register a custom shortcode:


function custom_short_description_func( ) {
	return get_the_excerpt();
}
add_shortcode( 'custom_short_description', 'custom_short_description_func' );

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

After that, you can show the content of this field in your template using this new shortcode:


[custom_short_description]

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2304899

My issue is resolved now. Thank you!