Image License Structured Data for Featured Images
Adds ImageObject JSON-LD with license, credit and copyright details for each post's featured image, which can earn the "Licensable" badge in Google Images.
Opens WPIDE on
Code
// Your image licensing details.
$wpide_image_license = array(
'license' => home_url( '/image-license/' ),
'acquire' => home_url( '/contact/' ),
'credit' => get_bloginfo( 'name' ),
'copyright' => '© ' . gmdate( 'Y' ) . ' ' . get_bloginfo( 'name' ),
);
add_action( 'wp_head', function () use ( $wpide_image_license ) {
if ( ! is_singular() || ! has_post_thumbnail( get_queried_object_id() ) ) {
return;
}
$data = array(
'@context' => 'https://schema.org',
'@type' => 'ImageObject',
'contentUrl' => get_the_post_thumbnail_url( get_queried_object_id(), 'full' ),
'license' => $wpide_image_license['license'],
'acquireLicensePage' => $wpide_image_license['acquire'],
'creditText' => $wpide_image_license['credit'],
'copyrightNotice' => $wpide_image_license['copyright'],
'creator' => array( '@type' => 'Organization', 'name' => $wpide_image_license['credit'] ),
);
echo '<script type="application/ld+json">' . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG ) . "</script>\n";
} );
Notes
Point the license and acquire-license URLs at real pages on your site that explain your image terms.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.