I am using the following code and toolset shortcode to trim text in the custom excerpt and still keep formatting but the text is shown with HTML tags. What could I be missing?
If I use wp_trim_words it shows the text but strips all formatting. If I use the code below, it keeps the formatting AND the HTML tags.
Hello and thank you for contacting Toolset support.
I assume that you meant by formatting the effect of some HTML tags, like "strong" or something else, right?
If that's the case, I'll suggest using strip_tags function before line 9 to remove HTML tags, but to keep some of them, that has to be passed in the second argument. For example:
Whenever you use trimming functions from PHP or WordPress, you will get the formatting lost. That's a design decision on how those functions work. If you need to keep the formatting, trimming and excerpt functions are most probably not the correct choice.
What if you split the field into multiple fields(context, objective, and format). Use single line fields if you don't need the user to use a WYSIWYG field. Then, you can have your own format markup for the displaying, you can programmatically decide how many words to display, and if you should display the "objective" and "format". Does it make sense?