-
user/pass provided below…
-
Alvind
Can you confirm whether the dynamic tag added in the Image URL field is using double curly braces? From the source, it appears that it is not: https://cln.sh/yFFXrMsbMgrB2hXJP79W
-
Hi all.
The dynamic tag is added in the styles panel > Backgrounds > Background Image.
When I add the field it has double-braces on it, but after saving, the outermost pair of braces disappear, leaving only the single pair you showed in your screenshot.
Oddly, when I display that element in Inspector, I do not see the style for .gb-element-4d922c3f at all.
I have added an admin account for you on the site, see below.
The GP Element containing the background is in the private info below. You will find the dynamic tag assigned to the very first container in the Element, the one labelled “Hero”.
-
Alvind
The dynamic tag is added in the styles panel > Backgrounds > Background Image.
The dynamic tag isn’t supported in that location. You’ll need to add it in the Inline Background Image field instead: https://cln.sh/lLMw9wfBLh4Fqf31TVL8
-
I moved the tag to the location you specified. It doesn’t work in that location either. The latest version of the code is pasted below. Based on the error_log() debugging output, the tag is registered, but sometimes the
'return' => '\AcornFinance\Customizations\get_hero_background_business_tag'is never called. Other times, it executes and produces this output to error_log():[22-Jul-2025 14:22:32 UTC] +++ Registering Hero Background Business Dynamic Tag [22-Jul-2025 14:22:33 UTC] +++ get_hero_background_business_tag called with options: Array ( [tag_name] => hero_background_business ) [22-Jul-2025 14:22:33 UTC] +++ Missing or empty default image URL, using default URL [22-Jul-2025 14:22:33 UTC] +++ Missing or empty af_hero_bg postmeta for ID 0Based on that output, it should return the value
'/wp-content/uploads/2025/06/Contractor-Hero-Background.webp'.The code is:
add_action( 'init', '\AcornFinance\Customizations\register_hero_background_business_dynamic_tag', 20 ); function register_hero_background_business_dynamic_tag() { error_log( "+++ Registering Hero Background Business Dynamic Tag" ); // if ( class_exists( 'GenerateBlocks_Register_Dynamic_Tag' ) ) { new \GenerateBlocks_Register_Dynamic_Tag( [ 'title' => __( 'Hero Background Business', 'generatepress-child' ), 'tag' => 'hero_background_business', 'type' => 'post', 'supports' => [ 'source' ], 'description' => __( 'Get the hero background image path for a business page.', 'generatepress-child' ), 'options' => [ 'default-image-url' => [ 'type' => 'text', 'label' => __( 'Default Image URL', 'generatepress-child' ), 'help' => __( 'Default image URL to use if no hero background is found.', 'generatepress-child' ), ], ], 'return' => '\AcornFinance\Customizations\get_hero_background_business_tag', ] ); // } } function get_hero_background_business_tag( $options, $block, $instance ) { error_log( "+++ get_hero_background_business_tag called with options: " . print_r( $options, true ) ); $defaultImageUrl = '/wp-content/uploads/2025/06/Contractor-Hero-Background.webp'; $id = isset( $options['id'] ) ? absint( $options['id'] ) : 0; if ( $id === 0 ) { $id = get_queried_object_id(); } $bkgImageUrl = isset( $options['default-image-url'] ) ? sanitize_url( $options['default-image-url'] ) : ''; if ( empty( $bkgImageUrl ) ) { error_log( "+++ Missing or empty default image URL, using default URL" ); $bkgImageUrl = $defaultImageUrl; } $heroBkgId = get_post_meta( $id, 'af_hero_bg', true ); if ( empty( $heroBkgId ) ) { error_log( "+++ Missing or empty af_hero_bg postmeta for ID {$id}" ); return $bkgImageUrl; } $imageAttr = wp_get_attachment_image_src( $heroBkgId, 'full' ); if ( empty( $imageAttr ) ) { error_log( "+++ Missing image attributes for attachment ID {$heroBkgId}" ); return $bkgImageUrl; } $imageUrl = $imageAttr[0]; if ( ! $imageUrl ) { error_log( "+++ Missing or empty image URL for attachment ID {$heroBkgId}" ); return $bkgImageUrl; } return parse_url( $imageUrl, PHP_URL_PATH ); } -
Just to be clear, it’s normal for the code to register but not execute when WP goes through a page with no tag.
-
Alvind
I’m not sure why you said it’s not working. I added the dynamic tag in the Inline Background Image field, and it appears to be working now. Could you confirm on your end?
I’m not certain whether the image being output is the correct one, so let me know if it’s not displaying as expected.
-
Hmm. I don’t know why it didn’t work before, but it’s working now. Thank you very much for your help.
I’d like to revisit a topic we discussed early in this thread…executing shortcodes in properties. You had mentioned that this was a known bug and that you were eventually going to work toward a fix. What’s the status on that? Or should I just plan on switching everything over to dynamic tags? We have a number of shortcodes in use within properties which I would rather not rewrite but I will if I have to.
-
Alvind
There is a similar bug that we’re aware of, but that one specifically relates to rendering shortcodes in the link field of the Button block. In that case, the shortcode is not being processed correctly – it simply outputs the raw shortcode instead of its rendered value. An issue has already been raised to address this, and I believe once that is resolved, the shortcode rendering issue in other fields will also be corrected.
However, there is no definitive timeline for a patch as of now.
-
At various points in this topic we discussed the possibility of using shortcodes as GB 2.x property values. At the time, this didn’t work but was considered a bug to be fixed someday. What’s the status of that? Shortcodes are somewhat easier to implement than dynamic tags.
-
Alvind
Hi there,
I believe the shortcode rendering issue was resolved in GenerateBlocks version 2.1.1.
Please try the shortcode method again, then let us know if it’s working as expected!
- You must be logged in to reply to this topic.