Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amy,
That is ok. Let me walk you through the steps.
So we have the custom code here:
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;
}
So this generates the shortcode [trim length="20"] [/trim]
Now to use this you need to add it to the Toolset Custom Code section in Toolset -> Settings -> Custom Code and hit Add New.
Then give the snippet a name. Now just add the code to the area and hit save and ensure that it is activated.
Once you have done this then you can now use this with your code.
[trim length="20"] [types field='heroic-acts'][/types][/trim]
Please let me know if further clarity is needed.
Thanks,
Shane
I did everything you said, but it didn't work.
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amy,
You actually did it correctly and it works fine.
The issue was that you only wrapped one of the shortcodes that you were using to display the content in the trim shortcode.
Have a look now.
Thanks,
Shane
I changed the word number from 20 to 10 and now it's not working....
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Amy,
I must apologize for this bring so frustrating for you but I can reassure you that it actually works. I had setup an example for you but it seems that it was removed.
However the correct way to do it is like this.
[trim length="20"] {!{types field='infilt-bullet-points'}!}{!{/types}!}[/trim]
[trim length="20"] [types field='heroic-acts'][/types][/trim]
It should be noted that the texts are not trimmed based on the words but rather based on the number of letters. So if you use 20 after the 20th letter then nothing else will be displayed.
I suggest using 200 .
Thanks,
Shane
I am such a dork!!! I was totally not putting the code in between the code you gave me!!!!
YOU ARE AWESOME!!! Thank you so much!!!
My issue is resolved now. Thank you!