PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.3
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / generators / schema / main-image.php

main-image.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.3, at src/generators/schema/main-image.php

47 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Generators\Schema;
4
5 use Yoast\WP\SEO\Config\Schema_IDs;
6
7 /**
8 * Returns ImageObject schema data.
9 */
10 class Main_Image extends Abstract_Schema_Piece {
11
12 /**
13 * Determines whether or not a piece should be added to the graph.
14 *
15 * @return bool
16 */
17 public function is_needed() {
18 return true;
19 }
20
21 /**
22 * Adds a main image for the current URL to the schema if there is one.
23 *
24 * This can be either the featured image or the first image in the content of the page.
25 *
26 * @return array|false Image Schema.
27 */
28 public function generate() {
29 $image_id = $this->context->canonical . Schema_IDs::PRIMARY_IMAGE_HASH;
30
31 // The featured image.
32 if ( $this->context->main_image_id ) {
33 $generated_schema = $this->helpers->schema->image->generate_from_attachment_id( $image_id, $this->context->main_image_id );
34 $this->context->main_image_url = $generated_schema['url'];
35
36 return $generated_schema;
37 }
38
39 // The first image in the content.
40 if ( $this->context->main_image_url ) {
41 return $this->helpers->schema->image->generate_from_url( $image_id, $this->context->main_image_url );
42 }
43
44 return false;
45 }
46 }
47