PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 19.0
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v19.0
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 / website.php

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

100 lines 2.6 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 schema Website data.
9 */
10 class Website 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 * Outputs code to allow recognition of the internal search engine.
23 *
24 * @return array Website data blob.
25 */
26 public function generate() {
27 $data = [
28 '@type' => 'WebSite',
29 '@id' => $this->context->site_url . Schema_IDs::WEBSITE_HASH,
30 'url' => $this->context->site_url,
31 'name' => $this->helpers->schema->html->smart_strip_tags( $this->context->site_name ),
32 'description' => \get_bloginfo( 'description' ),
33 ];
34
35 if ( $this->context->site_represents_reference ) {
36 $data['publisher'] = $this->context->site_represents_reference;
37 }
38
39 $data = $this->add_alternate_name( $data );
40 $data = $this->internal_search_section( $data );
41 $data = $this->helpers->schema->language->add_piece_language( $data );
42
43 return $data;
44 }
45
46 /**
47 * Returns an alternate name if one was specified in the Yoast SEO settings.
48 *
49 * @param array $data The website data array.
50 *
51 * @return array
52 */
53 private function add_alternate_name( $data ) {
54 $alternate_name = $this->helpers->options->get( 'alternate_website_name', '' );
55 if ( $alternate_name !== '' ) {
56 $data['alternateName'] = $this->helpers->schema->html->smart_strip_tags( $alternate_name );
57 }
58
59 return $data;
60 }
61
62 /**
63 * Adds the internal search JSON LD code to the homepage if it's not disabled.
64 *
65 * @link https://developers.google.com/search/docs/data-types/sitelinks-searchbox
66 *
67 * @param array $data The website data array.
68 *
69 * @return array
70 */
71 private function internal_search_section( $data ) {
72 /**
73 * Filter: 'disable_wpseo_json_ld_search' - Allow disabling of the json+ld output.
74 *
75 * @api bool $display_search Whether or not to display json+ld search on the frontend.
76 */
77 if ( \apply_filters( 'disable_wpseo_json_ld_search', false ) ) {
78 return $data;
79 }
80
81 /**
82 * Filter: 'wpseo_json_ld_search_url' - Allows filtering of the search URL for Yoast SEO.
83 *
84 * @api string $search_url The search URL for this site with a `{search_term_string}` variable.
85 */
86 $search_url = \apply_filters( 'wpseo_json_ld_search_url', $this->context->site_url . '?s={search_term_string}' );
87
88 $data['potentialAction'][] = [
89 '@type' => 'SearchAction',
90 'target' => [
91 '@type' => 'EntryPoint',
92 'urlTemplate' => $search_url,
93 ],
94 'query-input' => 'required name=search_term_string',
95 ];
96
97 return $data;
98 }
99 }
100