context = $context; $this->date = new WPSEO_Date_Helper(); } /** * Determines whether or not a piece should be added to the graph. * * @return bool */ public function is_needed() { if ( is_404() ) { return false; } return true; } /** * Returns WebPage schema data. * * @return array WebPage schema data. */ public function generate() { $data = [ '@type' => $this->determine_page_type(), '@id' => $this->context->canonical . WPSEO_Schema_IDs::WEBPAGE_HASH, 'url' => $this->context->canonical, 'inLanguage' => get_bloginfo( 'language' ), 'name' => $this->context->title, 'isPartOf' => [ '@id' => $this->context->site_url . WPSEO_Schema_IDs::WEBSITE_HASH, ], ]; if ( is_front_page() ) { if ( $this->context->site_represents_reference ) { $data['about'] = $this->context->site_represents_reference; } } if ( is_singular() ) { $this->add_image( $data ); $post = get_post( $this->context->id ); $data['datePublished'] = $this->date->format( $post->post_date_gmt ); $data['dateModified'] = $this->date->format( $post->post_modified_gmt ); if ( get_post_type( $post ) === 'post' ) { $data = $this->add_author( $data, $post ); } } if ( ! empty( $this->context->description ) ) { $data['description'] = strip_tags( $this->context->description, '