Skip Navigation

[Resolved] Using Shortcode in Gutenberg

This support ticket is created 3 years, 6 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/Hong_Kong (GMT+08:00)

This topic contains 8 replies, has 2 voices.

Last updated by Pete 3 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#2032757

Hi there,

Trying to limit the text shown and saw this post in Toolset Support:
https://toolset.com/forums/topic/limiting-field-length-to-display/

If I'm working to this principle I should be add:

[show_field_with_limit length="140"]
[types field="'property-detail" output="raw"][/types]
[/show_field_with_limit]

But how? No matter what I add this to the code is removed.

Any thoughts ref this would be great, can't even test if this works and if this will be a solution to what we need.

Many thanks, Pete

#2032881

Hello,

I suggest you try the solution of below thread:
https://toolset.com/forums/topic/cannot-find-field-options-under-the-single-field-setting/#post-1886537

And above custom shortcode is using function mb_strimwidth() to truncate string, this will work in non-English characters:
hidden link

To insert the custom shortcode into Gutenberg editor, please try WordPress built-in "Shortcode" block, see WP document:
https://wordpress.org/support/article/shortcode-block/

#2032959

Hi there Lou,

Thank you, appreciate the help.

Ok I got this working great following steps 1 and 3 however I didn't understand what I would do ref:

And above custom shortcode is using function mb_strimwidth() to truncate string, this will work in non-English characters:
hidden link

I followed 1 and 3 and used this shortcode: [mb_strim_title length="20"][types field='property-details'][/mb_strim_title]

Should I be using something else?

#2033573

I have tried it in my localhost with a fresh WP installation, it works fine, if you need more assistance for it, please provide a test site with the same problem, also point out the problem page/post URL, and where I can edit your custom PHP codes, I need a live website to test and debug, thanks

#2033803

Hi Luo,

Well that was my issue, I used it and it worked fine.
I couldn't work out why you sent:

And above custom shortcode is using function mb_strimwidth() to truncate string, this will work in non-English characters:
hidden link

#2033813

For the PHP function mb_strimwidth(), please check the PHP document here:
hidden link
And
hidden link

When you manipulate (trim, split, splice, etc.) strings encoded in a multibyte encoding, you need to use special functions since two or more consecutive bytes may represent a single character in such encoding schemes. Otherwise, if you apply a non-multibyte-aware string function to the string, it probably fails to detect the beginning or ending of the multibyte character and ends up with a corrupted garbage string that most likely loses its original meaning.

#2034373

Hi Luo,

Ok, I don't understand half of what this is. I'm no developer so can we keep this straight forward please.

I'm using this shortcode:
[mb_strim_title length="530"][types field='property-details'][/mb_strim_title]

It works. You said you tested it, and it also works?

Either way I'm just looking for a straight forward way of getting this to work...it seems to be!

You're adding far more, confusing information here that I simply don't understand or need.

I have had to add this to the Fields and Text block as the shortcode block has no ability to add a class or to style the text.
It still works.

Just need to know if this is ok and stable.

Thank you.

#2034827

You can use a Toolset container block to wrap the shortcode block, and add CSS class names, style it with CSS codes easily:
https://toolset.com/course-lesson/container-blocks/

#2035349

My issue is resolved now. Thank you!