Archived topic
Filter hook for Theme builder's dynamic data
24 replies · Started by Ash on March 27, 2021
Is there a filter hook for dynamic data output?
I would like to customize the output through a hook.
Hi there,
Yes, there are various filters throughout the dynamic data.
What are you trying to filter? Happy to help in here until we're able to add the filters to our documentation.
e.g.
- converting unit of a number.
- modifying text conditionally such as per page language.
- decorating dynamic data such as text into a badge(like [SALE!] badge)
Thank you.
I mean the Heading block.
So for Heading text, we have this filter: generate_dynamic_text_title
It has two parameters:
1. $post_title - the returned dynamic title.
2. $block - all of the block data given to us by the render_block filter: https://developer.wordpress.org/reference/hooks/render_block/
Let me know if you need more info :)
Thank you.
Somehow I can access only single heading module on the content template...?
You could do something like this:
add_filter( 'generate_dynamic_text_title', function( $text, $block ) {
$text_to_replace = ! empty( $block['attrs']['gpDynamicTextReplace'] ) ? $block['attrs']['gpDynamicTextReplace'] :'';
if ( 'Your saved preview text' === $text_to_replace ) {
$text = 'Your new dynamic text';
}
return $text;
}, 10, 2);
Still I can access only first heading.
Second and later are ignored.
I thought something like this would work. but doesn't work.
function my_gp_dynamic_text_title($block_content, $block){
if(strpos($block['attrs']['className'],'aaa')!==FALSE){ $block_content = 'aaa'; }
elseif(strpos($block['attrs']['className'],'bbb')!==FALSE){ $block_content = 'bbb'; }
elseif(strpos($block['attrs']['className'],'ccc')!==FALSE){ $block_content = 'ccc'; }
return $block_content;
}
add_filter( 'generate_dynamic_text_title', 'my_gp_dynamic_text_title', 10, 2 );
Are the "second and later" Headlines using the same preview text?
The function I shared should apply to ALL Headline blocks using Your saved preview text as the preview text.
Not sure since I can not access other headings.
On the Block Editor, I see different text on each.
This function outputs $block only once per content template.
It's kinda strange.
function my_gp_dynamic_text_title($block_content, $block){
print_r($block);
return $block_content;
}
add_filter( 'generate_dynamic_text_title', 'my_gp_dynamic_text_title', 10, 2 );
Any chance you can link me to the page with that snippet active?
Here is the link
So the var_dump is executing on every title.
In that case, this should work:
add_filter( 'generate_dynamic_text_title', function( $text, $block ) {
$text_to_replace = ! empty( $block['attrs']['gpDynamicTextReplace'] ) ? $block['attrs']['gpDynamicTextReplace'] :'';
if ( 'Post Title' === $text_to_replace ) {
$text = 'Your new dynamic text';
}
return $text;
}, 10, 2);