-
Patrick
Hi all,
I would like to add custom Dynamic Content options to GB Blocks, how is this possible?
Example:
I have created a Custom Content Type (CCT) with a meta field “my_image” (Media ID), and would like to load this image as dynamic background image for a GB Container Block. The CCT Author ID equals the current post author ID.
Appreciate your help with this.
Thanks,
Patrick -
Hi there,
if the
my_image
meta field is saved to the current post meta, then you can select a Container Block, and in the Dynamic Setting set the Content Source toPost Meta
and add your field name.Let me know if i am missing anything.
-
Patrick
Hi David,
Thanks for your fast reply.
There is no data of my CCT written to postmeta. That’s why I have to use custom coding to pull the related data. Could you please advice how to add a custom option where I can run my custom coding to fill background image path dynamically ?
Are there any hooks for this ?
Thanks
-
Fernando
Hi Patrick,
If
my_image
is not a post meta, how do you pull its value through custom code? -
Patrick
Hi Fernando,
I have a custom table with a column author id which equals to the Post author id. So in my custom coding I query my table by author and pull all fields needed for dynamic content.
Thanks
-
Ah ok, so you have the
generateblocks_background_image_url
filter hook.See for an example:
https://generatepress.com/forums/topic/woocommerce-element-background/#post-2531489
And you can see it here:
-
Patrick
Hi David,
Thanks for the provided hook. This works for now :)!
However I do have more image and text fields that I need to fill dynamically. That’s why I was asking if I can’t add my custom Dynamic Content option to your dropdown. This would make it way more easy for me instead of using multiple hooks and CSS classes.
Any possibility to add custom options here?
Thanks
-
Patrick
Hi David,
If my previous request is not possible (yet), could you please also provide me the hook to show custom content for GB Button Text ?
Thanks! 🙂
-
Fernando
Your request isn’t possible yet.
Here’s the filter you’re looking for: https://github.com/tomusborne/generateblocks/blob/88590c3168d62613f9ba76e5e9d15ddac6590e24/includes/class-dynamic-content.php#:~:text=generateblocks_dynamic_content_output
generateblocks_dynamic_content_output
Here’s a sample code of its usage:
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){ if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'convert-to-fjy' ) !== false ) { $timestamp = strtotime($content); $my_date = sprintf( '<time datetime="%1$s">%2$s</time>', date('c', $timestamp), date('l F j, Y', $timestamp) ); return $my_date; } return $content; }, 10, 3);
-
Patrick
Hi Fernando,
Thanks for your fast reply and provided filter. That works for now 🙂
Appreciate your support.
-
Fernando
You’re welcome, Patrick! 🙂
- You must be logged in to reply to this topic.