# Auto add json+ld for photo module images

**URL:** <https://community.wpbeaverbuilder.com/t/auto-add-json-ld-for-photo-module-images/14310>\
**Category:** Snippets\
**Created:** [April 13, 2021, 9:14pm UTC](https://community.wpbeaverbuilder.com/t/auto-add-json-ld-for-photo-module-images/14310 "2021-04-13T21:14:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pross](https://community.wpbeaverbuilder.com/user_avatar/community.wpbeaverbuilder.com/pross/32/883_2.png) [@pross](https://community.wpbeaverbuilder.com/u/pross)\
**Post date:** [April 13, 2021, 9:14pm UTC](https://community.wpbeaverbuilder.com/t/auto-add-json-ld-for-photo-module-images/14310/1 "2021-04-13T21:14:28Z")

</div>

```
add_action( 'fl_builder_before_render_module', function( $module ) {
	if ( $module instanceof FLPhotoModule ) {
		if ( ! empty( $module->settings->photo_src ) ) {
			$output = '';
			$parts = array(
				'@context' => 'https://schema.org/',
				'@type' => 'ImageObject',
				'contentUrl' => $module->settings->photo_src,
				'license' => 'https://example.com/license',
				'acquireLicensePage' => 'https://example.com/how-to-use-my-images',
			);

			// output this
			$output .= '<script type="application/ld+json">[{';
			foreach ( $parts as $type => $value ) {
				$output .= sprintf( '"%s": "%s",', $type, $value );
			}
			$output = rtrim( $output, ',' ) . '}]</script>';
			echo $output;
		}
	}
});
```
