Changeset 12202
- Timestamp:
- 11/04/2022 06:30:19 AM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/photo-directory/inc/head.php
r11679 r12202 16 16 add_filter( 'document_title_separator', [ __CLASS__, 'document_title_separator' ] ); 17 17 add_filter( 'wp_resource_hints', [ __CLASS__, 'wp_resource_hints' ], 10, 2 ); 18 add_action( 'wp_head', [ __CLASS__, 'json_ld_schema' ], 1 ); 18 19 } 19 20 … … 69 70 } 70 71 72 /** 73 * Outputs structured data. 74 */ 75 public static function json_ld_schema() { 76 $schema = false; 77 78 // Schema for individual photo pages. 79 if ( is_singular( Registrations::get_post_type() ) && 'publish' === get_post_status( get_queried_object_id() ) ) { 80 $contributor_name = get_the_author_meta( 'display_name', get_queried_object()->post_author ); 81 $schema = [ 82 "@context" => 'https://schema.org', 83 "@type" => 'ImageObject', 84 'contentUrl' => wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' )[0] ?? '', 85 'license' => 'https://creativecommons.org/share-your-work/public-domain/cc0/', 86 'acquireLicensePage' => "https://wordpress.org/photos/license/", 87 'creditText' => $contributor_name, 88 'creator' => [ 89 '@type' => 'Person', 90 'name' => $contributor_name, 91 ], 92 'copyrightNotice' => $contributor_name, 93 ]; 94 } 95 96 // Print the schema. 97 if ( $schema ) { 98 echo PHP_EOL, '<script type="application/ld+json">', PHP_EOL; 99 // Output URLs without escaping the slashes, and print it human readable. 100 echo wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT ); 101 echo PHP_EOL, '</script>', PHP_EOL; 102 } 103 } 104 71 105 } 72 106
Note: See TracChangeset
for help on using the changeset viewer.