Skip Navigation

[Resolved] clear formatting from previous item in archive loop

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.

This topic contains 2 replies, has 2 voices.

Last updated by jimP 5 months, 1 week ago.

Assigned support staff: Waqar.

Author
Posts
#1523809

Tell us what you are trying to do?
I've used a recommended shortcode to truncate a long field in archive display, but one entry includes italics, which I need to clear prior to the next record display.

Is there any documentation that you are following?
No...searched and no easy Toolset solution found.

Is there a similar example that we can see?
For behavior, see hidden link

Further information: see https://toolset.com/forums/topic/truncate-text-field-in-blocks-editor/ for the shortcode I used to truncate a long WYSIWYG field. One person began this field with a quote in italics, hence the truncated extract ends in italics, which is continued on all subsequent records in the archive view.

Perhaps there is something I can add to the shortcode, or as an additional block in the archive loop following the shortcode, to clear this, and possibly other, formatting?

Jim P.

#1524467

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Jim,

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

The challenge here is that while truncating the long content from the field, we'll not know exactly which HTML tag will be available and at which position specifically its opening and closing tags exist.

The safest and efficient approach, in this case, would be to strip all HTML tags from such content when truncating it, through the "wp_strip_all_tags" function.
( ref: https://developer.wordpress.org/reference/functions/wp_strip_all_tags/ )

For example, assuming you're still using the shortcode from the other support thread ( ref: https://toolset.com/forums/topic/truncate-text-field-in-blocks-editor/#post-1470587 ), line# 3 will change from:


$content = do_shortcode($content);

To:


$content = do_shortcode($content);
$content = wp_strip_all_tags($content);

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

regards,
Waqar

#1529713

My issue is resolved now. Thank you!