-
mgkmoha
I want to limit the number of characters displayed in the product title. I’m currently using the Heading block to show the title. Is there a way to achieve this through block settings, or are there any hooks or filters available that can be applied when using the GP Query block.
-
Hi there,
The screenshot is selecting the list of terms, is this what you are referring to?
Or is there a headline to pull the product title?
Just to make sure you are trying to show a shorter version of the product title, right?
-
mgkmoha
Correct, there is a headline block to pull the product title and show the shorter version. In addition, I want this to be filtered by characters rather than words.
-
Hi there,
A PHP snippet like this may help:
add_filter( 'generateblocks_dynamic_content_output', function( $content, $attributes ) { $class_name = $attributes['className'] ?? ''; if ( 'truncate-text' !== $class_name ) { return $content; } $number_of_characters = 10; $content = mb_strimwidth( $content, 0, $number_of_characters, '...' ); return $content; }, 10, 2 );
In order for this to work, you need to give the block this CSS class in the “Advanced” panel:
truncate-text
Let me know if it helps or not 🙂
-
mgkmoha
Hi Tom!
Thank you for sharing the snippet.
This helped me a lot. -
Glad I could help!
- You must be logged in to reply to this topic.