namespace Yoast\WP\SEO\Presentations;
use Yoast\WP\SEO\Context\Meta_Tags_Context;
use Yoast\WP\SEO\Generators\Breadcrumbs_Generator;
use Yoast\WP\SEO\Generators\Open_Graph_Image_Generator;
use Yoast\WP\SEO\Generators\Open_Graph_Locale_Generator;
use Yoast\WP\SEO\Generators\Schema_Generator;
use Yoast\WP\SEO\Generators\Twitter_Image_Generator;
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
use Yoast\WP\SEO\Helpers\Image_Helper;
use Yoast\WP\SEO\Helpers\Indexable_Helper;
use Yoast\WP\SEO\Helpers\Open_Graph\Values_Helper;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Helpers\Permalink_Helper;
use Yoast\WP\SEO\Helpers\Url_Helper;
use Yoast\WP\SEO\Helpers\User_Helper;
use Yoast\WP\SEO\Models\Indexable;
* Class Indexable_Presentation.
* Presentation object for indexables.
* @property string $title
* @property string $meta_description
* @property array $robots
* @property string $canonical
* @property string $rel_next
* @property string $rel_prev
* @property string $open_graph_type
* @property string $open_graph_title
* @property string $open_graph_description
* @property array $open_graph_images
* @property string $open_graph_url
* @property string $open_graph_site_name
* @property string $open_graph_article_publisher
* @property string $open_graph_article_author
* @property string $open_graph_article_published_time
* @property string $open_graph_article_modified_time
* @property string $open_graph_locale
* @property string $open_graph_fb_app_id
* @property array $schema
* @property string $twitter_card
* @property string $twitter_title
* @property string $twitter_description
* @property string $twitter_image
* @property string $twitter_creator
* @property string $twitter_site
* @property array $source
* @property array $breadcrumbs
* @property int $estimated_reading_time_minutes
class Indexable_Presentation extends Abstract_Presentation {
protected $schema_generator;
* The Open Graph image generator.
* @var Open_Graph_Image_Generator
protected $open_graph_image_generator;
* The Twitter image generator.
* @var Twitter_Image_Generator
protected $twitter_image_generator;
* The Open Graph locale generator.
* @var Open_Graph_Locale_Generator
private $open_graph_locale_generator;
* The breadcrumbs generator.
* @var Breadcrumbs_Generator
private $breadcrumbs_generator;
* The current page helper.
* @var Current_Page_Helper
protected $indexable_helper;
protected $permalink_helper;
protected $values_helper;
* Sets the generator dependencies.
* @param Schema_Generator $schema_generator The schema generator.
* @param Open_Graph_Locale_Generator $open_graph_locale_generator The Open Graph locale generator.
* @param Open_Graph_Image_Generator $open_graph_image_generator The Open Graph image generator.
* @param Twitter_Image_Generator $twitter_image_generator The Twitter image generator.
* @param Breadcrumbs_Generator $breadcrumbs_generator The breadcrumbs generator.
public function set_generators(
Schema_Generator $schema_generator,
Open_Graph_Locale_Generator $open_graph_locale_generator,
Open_Graph_Image_Generator $open_graph_image_generator,
Twitter_Image_Generator $twitter_image_generator,
Breadcrumbs_Generator $breadcrumbs_generator
$this->schema_generator = $schema_generator;
$this->open_graph_locale_generator = $open_graph_locale_generator;
$this->open_graph_image_generator = $open_graph_image_generator;
$this->twitter_image_generator = $twitter_image_generator;
$this->breadcrumbs_generator = $breadcrumbs_generator;
* Used by dependency injection container to inject the helpers.
* @param Image_Helper $image The image helper.
* @param Options_Helper $options The options helper.
* @param Current_Page_Helper $current_page The current page helper.
* @param Url_Helper $url The URL helper.
* @param User_Helper $user The user helper.
* @param Indexable_Helper $indexable The indexable helper.
* @param Permalink_Helper $permalink The permalink helper.
* @param Values_Helper $values The values helper.
public function set_helpers(
Current_Page_Helper $current_page,
Indexable_Helper $indexable,
Permalink_Helper $permalink,
$this->options = $options;
$this->current_page = $current_page;
$this->indexable_helper = $indexable;
$this->permalink_helper = $permalink;
$this->values_helper = $values;
* Gets the permalink from the indexable or generates it if dynamic permalinks are enabled.
* @return string The permalink.
public function get_permalink() {
if ( $this->indexable_helper->dynamic_permalinks_enabled() ) {
return $this->permalink_helper->get_permalink_for_indexable( $this->model );
return $this->model->permalink;
* @return string The title.
public function generate_title() {
if ( $this->model->title ) {
return $this->model->title;
* Generates the meta description.
* @return string The meta description.
public function generate_meta_description() {
if ( $this->model->description ) {
return $this->model->description;
* Generates the robots value.
* @return array The robots value.
public function generate_robots() {
$robots = $this->get_base_robots();
return $this->filter_robots( $robots );
* Gets the base robots value.
* @return array The base robots value.
protected function get_base_robots() {
'index' => ( $this->model->is_robots_noindex === true ) ? 'noindex' : 'index',
'follow' => ( $this->model->is_robots_nofollow === true ) ? 'nofollow' : 'follow',
'max-snippet' => 'max-snippet:-1',
'max-image-preview' => 'max-image-preview:large',
'max-video-preview' => 'max-video-preview:-1',
* Run the robots output content through the `wpseo_robots` filter.
* @param array $robots The meta robots values to filter.
* @return array The filtered meta robots values.
protected function filter_robots( $robots ) {
// Remove values that are only listened to when indexing.
if ( $robots['index'] === 'noindex' ) {
$robots['imageindex'] = null;
$robots['archive'] = null;
$robots['snippet'] = null;
$robots['max-snippet'] = null;
$robots['max-image-preview'] = null;
$robots['max-video-preview'] = null;
$robots_string = \implode( ', ', \array_filter( $robots ) );
* Filter: 'wpseo_robots' - Allows filtering of the meta robots output of Yoast SEO.
* @api string $robots The meta robots directives to be echoed.
* @param Indexable_Presentation $presentation The presentation of an indexable.
$robots_filtered = \apply_filters( 'wpseo_robots', $robots_string, $this );
// Convert the robots string back to an array.
if ( \is_string( $robots_filtered ) ) {
$robots_values = \explode( ', ', $robots_filtered );
foreach ( $robots_values as $value ) {
// Change `noindex` to `index.
if ( \strpos( $key, 'no' ) === 0 ) {
$key = \substr( $value, 2 );
// Change `max-snippet:-1` to `max-snippet`.
$colon_position = \strpos( $key, ':' );
if ( $colon_position !== false ) {
$key = \substr( $value, 0, $colon_position );
$robots_new[ $key ] = $value;
if ( ! $robots_filtered ) {
* Filter: 'wpseo_robots_array' - Allows filtering of the meta robots output array of Yoast SEO.
* @api array $robots The meta robots directives to be used.
* @param Indexable_Presentation $presentation The presentation of an indexable.
return \apply_filters( 'wpseo_robots_array', \array_filter( $robots ), $this );
* Generates the robots value for the googlebot tag.
* @deprecated 14.9 Values merged into the robots meta tag.
* @return array The robots value with opt-in snippets.
public function generate_googlebot() {
\_deprecated_function( __METHOD__, 'WPSEO 14.9' );
* Generates the value for the bingbot tag.
* @deprecated 14.9 Values merged into the robots meta tag.
* @return array The robots value with opt-in snippets.
public function generate_bingbot() {
\_deprecated_function( __METHOD__, 'WPSEO 14.9' );
* Generates the canonical.
* @return string The canonical.
public function generate_canonical() {
if ( $this->model->canonical ) {
return $this->model->canonical;
$permalink = $this->get_permalink();
* Generates the rel prev.
* @return string The rel prev value.
public function generate_rel_prev() {
* Generates the rel next.
* @return string The rel prev next.
public function generate_rel_next() {
* Generates the Open Graph type.
* @return string The Open Graph type.
public function generate_open_graph_type() {
* Generates the open graph title.
* @return string The open graph title.
public function generate_open_graph_title() {
if ( $this->model->open_graph_title ) {
$open_graph_title = $this->model->open_graph_title;
if ( empty( $open_graph_title ) ) {
// The helper applies a filter, but we don't have a default value at this stage so we pass an empty string.
$open_graph_title = $this->values_helper->get_open_graph_title( '', $this->model->object_type, $this->model->object_sub_type );
if ( empty( $open_graph_title ) ) {
$open_graph_title = $this->title;
return $open_graph_title;
* Generates the open graph description.
* @return string The open graph description.
public function generate_open_graph_description() {
if ( $this->model->open_graph_description ) {
$open_graph_description = $this->model->open_graph_description;
if ( empty( $open_graph_description ) ) {
// The helper applies a filter, but we don't have a default value at this stage so we pass an empty string.
$open_graph_description = $this->values_helper->get_open_graph_description( '', $this->model->object_type, $this->model->object_sub_type );
if ( empty( $open_graph_description ) ) {
$open_graph_description = $this->meta_description;
return $open_graph_description;
* Generates the open graph images.
* @return array The open graph images.
public function generate_open_graph_images() {
if ( $this->context->open_graph_enabled === false ) {
return $this->open_graph_image_generator->generate( $this->context );
* Generates the open graph image ID.
* @return string The open graph image ID.
public function generate_open_graph_image_id() {
if ( $this->model->open_graph_image_id ) {
return $this->model->open_graph_image_id;
return $this->values_helper->get_open_graph_image_id( 0, $this->model->object_type, $this->model->object_sub_type );
* Generates the open graph image URL.
* @return string The open graph image URL.