Navigation überspringen

[Gelöst] Trim data from a custom field when displaying it

This support ticket is created vor 1 year, 6 months. 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
- 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 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 1 reply, hat 1 Stimme.

Zuletzt aktualisiert von gabrielB vor 1 year, 6 months.

Assistiert von: Minesh.

Author
Artikel
#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 -> versteckter Link

#2784986

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: 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.