Skip Navigation

[Resolved] Trim data from a custom field when displaying it

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 1 voice.

Last updated by gabrielB 1 day, 1 hour ago.

Assisted by: Minesh.

Author
Posts
#2784975
Screenshot 2024-11-21 at 13.35.16.png

I'm trying to trim data from a custom field when displaying it.

I found this, but it's not working as it should: https://toolset.com/forums/topic/strim-a-custom-field/

You can see the issue on the home page, in the reviews section -> hidden link

#2784986

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You shared the reference ticket:
- https://toolset.com/forums/topic/strim-a-custom-field/

Have you added the custom shortcode to "Custom Code" offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

add_shortcode('trim', 'trim_shortcode');
function trim_shortcode($atts, $content = '') {
$content = do_shortcode($content);
$length = (int)$atts['length'];
if (strlen($content) > $length) {
$content = substr($content, 0, $length) . '…';
}
return $content;
}
#2784987

Thanks again, Minesh.