Skip Navigation

[Resolved] Issue with [word_trim_custom words="40" more="…."]…

This support ticket is created 2 years, 3 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 8 replies, has 2 voices.

Last updated by jeanL-2 2 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2262095

Tell us what you are trying to do?

I want to limit the number of words in the display of a dynamic text. This is text in a bootstrap view. This works well until you change the search criteria. As soon as the criteria are changed and the corresponding items are displayed, a line of text or code appears on the screen.

Is there any documentation that you are following?

Yes : https://toolset.com/forums/topic/set-limit-number-of-words-or-character-for-custom-field-output-on-front-end-grid/

Is there a similar example that we can see?

hidden link

What is the link to your site?
hidden link

#2262493

Waqar
Supporter

Languages: English (English )

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

Hi,

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

While I can see the issue on your website when the search is performed, I couldn't reproduce this on my test website.

I have the admin access details, but, I'll need your permission to download a clone/snapshot of the website, to investigate this on a different server.

regards,
Waqar

#2262499

Hi Waqar,

Happy to hear from you, hope your well. You have the permission to download a clone.

regards,

Jean

#2263433

Waqar
Supporter

Languages: English (English )

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

Thank you for the permission and I've downloaded the duplicator package.

I'll be performing some tests and will share the findings accordingly.

Thank you for your patience.

#2263517

Ok thanks

#2264537

Waqar
Supporter

Languages: English (English )

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

Thank you for waiting.

During troubleshooting on your website's clone, I noticed that the custom shortcode that you are using from the other ticket is not compatible with AJAX requests, when the Elementor plugin is being used.

For this particular requirement, you can register a new custom shortcode:


function word_trim_custom_func( $atts, $content = null ) {
	$a = shortcode_atts( array(
		'words' => '18',
		'more' => '...',
		'field' => ''
	), $atts );
	
	$output = do_shortcode('[types field="'.$a['field'].'" output="raw" suppress_filters="true"][/types]');

	if (!empty($output)) {
		return wp_trim_words( $output, $a['words'], $a['more'] );
	}
}
add_shortcode( 'word_trim_custom', 'word_trim_custom_func' );

And in your content template, you can use this new shortcode, like this:


[word_trim_custom_field words="20" more="...." field="mettre-un-tres-court-descriptif-2-lignes-maximum"]

In this example, I've used the field slug "mettre-un-tres-court-descriptif-2-lignes-maximum", but you can replace it with other text or WYSIWYG field slugs too.

#2264887
vue 1.JPG
vue 2.JPG
vue 3.JPG

Hi Waqar and thanks for your mail,

I did what you asked, I integrated the code in functions.php, and I integrated the shortcode in the tooset template as mentioned but instead of the text it's the code [word_trim_custom_field words="20" more="...." field="put-a-short-description-2-lines-maximum"] that displays...

#2265525

Waqar
Supporter

Languages: English (English )

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

I apologize as there were some typos in my last reply and the correct name for the shortcode was not used.

Here is the code with the correct shortcode name and you can replace it in your theme's "functions.php" file:


function word_trim_custom_field_func( $atts, $content = null ) {
    $a = shortcode_atts( array(
        'words' => '18',
        'more' => '...',
        'field' => ''
    ), $atts );
     
    $output = do_shortcode('[types field="'.$a['field'].'" output="raw" suppress_filters="true"][/types]');
 
    if (!empty($output)) {
        return wp_trim_words( $output, $a['words'], $a['more'] );
    }
}
add_shortcode( 'word_trim_custom_field', 'word_trim_custom_field_func' );

#2266329

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.