meta_resolver = $meta_resolver; $this->post_meta = $post_meta; } public function get_id(): string { return 'WebPage'; } public function applies_to( \WP_Post $post ): bool { // M66: a user-forced type (or 'none') supersedes automatic detection — // ForcedSchemaType emits the main node instead (or nothing at all). if ( '' !== ForcedSchemaType::override_for( $this->post_meta, $post ) ) { return false; } return 'post' !== $post->post_type; } public function build( \WP_Post $post ): array { $title = $this->meta_resolver->title( $post ); $title = '' !== $title ? $title : get_the_title( $post ); $data = array( '@type' => 'WebPage', '@id' => (string) get_permalink( $post ) . '#webpage', 'url' => (string) get_permalink( $post ), 'name' => wp_strip_all_tags( $title ), 'description' => $this->meta_resolver->description( $post ), 'isPartOf' => array( '@id' => SchemaIds::website() ), 'datePublished' => get_the_date( DATE_W3C, $post ), 'dateModified' => get_the_modified_date( DATE_W3C, $post ), ); $image = $this->meta_resolver->og_image_url( $post ); if ( '' !== $image ) { $data['primaryImageOfPage'] = $image; } /** * Filters the WebPage schema node for non-'post' content * (pages and custom post types). * * @param array $data * @param \WP_Post $post */ return (array) apply_filters( 'acez_seo_webpage', $data, $post ); } }