Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Adding custom Dynamic Content options

  • 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 to Post Meta and add your field name.

    Let me know if i am missing anything.

  • 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

  • Hi Patrick,

    If my_image is not a post meta, how do you pull its value through custom code?

  • 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

  • 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

  • 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! 🙂

  • 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);
  • Hi Fernando,

    Thanks for your fast reply and provided filter. That works for now 🙂

    Appreciate your support.

  • You’re welcome, Patrick! 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.