PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.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 / integrations / third-party / web-stories.php

web-stories.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at src/integrations/third-party/web-stories.php

103 lines 2.8 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\Integrations\Third_Party;
4
5 use Yoast\WP\SEO\Conditionals\Web_Stories_Conditional;
6 use Yoast\WP\SEO\Integrations\Front_End_Integration;
7 use Yoast\WP\SEO\Integrations\Integration_Interface;
8 use Yoast\WP\SEO\Models\Indexable;
9 use Yoast\WP\SEO\Presentations\Indexable_Presentation;
10
11 /**
12 * Web Stories integration.
13 */
14 class Web_Stories implements Integration_Interface {
15
16 /**
17 * The front end integration.
18 *
19 * @var Front_End_Integration
20 */
21 protected $front_end;
22
23 /**
24 * Returns the conditionals based in which this loadable should be active.
25 *
26 * @return array
27 */
28 public static function get_conditionals() {
29 return [ Web_Stories_Conditional::class ];
30 }
31
32 /**
33 * Constructs the Web Stories integration
34 *
35 * @param Front_End_Integration $front_end The front end integration.
36 */
37 public function __construct( Front_End_Integration $front_end ) {
38 $this->front_end = $front_end;
39 }
40
41 /**
42 * Initializes the integration.
43 *
44 * This is the place to register hooks and filters.
45 *
46 * @return void
47 */
48 public function register_hooks() {
49 \add_action( 'web_stories_enable_metadata', '__return_false' );
50 \add_action( 'web_stories_enable_schemaorg_metadata', '__return_false' );
51 \add_action( 'web_stories_enable_open_graph_metadata', '__return_false' );
52 \add_action( 'web_stories_enable_twitter_metadata', '__return_false' );
53
54 \add_action( 'web_stories_story_head', [ $this, 'web_stories_story_head' ], 1 );
55 \add_filter( 'wpseo_schema_article_type', [ $this, 'filter_schema_article_type' ], 10, 2 );
56 \add_filter( 'wpseo_metadesc', [ $this, 'filter_meta_description' ], 10, 2 );
57 }
58
59 /**
60 * Hooks into web story <head> generation to modify output.
61 *
62 * @return void
63 */
64 public function web_stories_story_head() {
65 \remove_action( 'web_stories_story_head', 'rel_canonical' );
66 \add_action( 'web_stories_story_head', [ $this->front_end, 'call_wpseo_head' ], 9 );
67 }
68
69 /**
70 * Filters the meta description for stories.
71 *
72 * @param string $description The description sentence.
73 * @param Indexable_Presentation $presentation The presentation of an indexable.
74 * @return string The description sentence.
75 */
76 public function filter_meta_description( $description, $presentation ) {
77 if ( $description || $presentation->model->object_sub_type !== 'web-story' ) {
78 return $description;
79 }
80
81 return \get_the_excerpt( $presentation->model->object_id );
82 }
83
84 /**
85 * Filters Article type for Web Stories.
86 *
87 * @param string|string[] $type The Article type.
88 * @param Indexable $indexable The indexable.
89 * @return string|string[] Article type.
90 */
91 public function filter_schema_article_type( $type, $indexable ) {
92 if ( $indexable->object_sub_type !== 'web-story' ) {
93 return $type;
94 }
95
96 if ( \is_string( $type ) && $type === 'None' ) {
97 return 'Article';
98 }
99
100 return $type;
101 }
102 }
103