/** * Inject ImageGallery JSON-LD whenever a FooGallery block is present on a page. * Works with Gutenberg blocks and shortcodes — no JS or lazy-load dependency. */ add_action('astra_entry_after', function() { global $post; if ( ! $post ) return; // Detect FooGallery blocks if ( ! has_block('foogallery/gallery', $post) ) return; // Extract gallery IDs from block JSON preg_match_all('/"blockName":"foogallery\/gallery".*?"id":(\d+)/', $post->post_content, $matches); $gallery_ids = array_unique(array_map('intval', $matches[1])); if ( empty($gallery_ids) ) return; foreach ($gallery_ids as $gid) { if ( ! function_exists('foogallery_get_gallery_attachments') ) continue; $atts = foogallery_get_gallery_attachments($gid); if ( empty($atts) ) continue; $images = []; foreach ($atts as $att) { $src = wp_get_attachment_image_src($att->ID, 'full'); if ( ! $src ) continue; $alt = get_post_meta($att->ID, '_wp_attachment_image_alt', true); $title = get_the_title($att->ID); $images[] = [ '@type' => 'ImageObject', 'url' => $src[0], 'name' => $title, 'caption' => $alt ?: $title, 'width' => $src[1], 'height' => $src[2], ]; } if ( ! $images ) continue; $schema = [ '@context' => 'https://schema.org', '@type' => 'ImageGallery', '@id' => get_permalink($gid) . '#imagegallery', 'name' => get_the_title($gid), 'url' => get_permalink($gid), 'hasPart' => $images, 'creator' => [ '@type'=> 'Person', 'name' => 'Chad Davis', 'url' => 'https://chaddavis.photography', ], 'copyrightNotice'=> '© 2025 Chad Davis Photography', ]; echo ''; } }, 25); Target Headquarters Photography | Chad Davis Photography