ress Core from outputting a robots tag in disableWpRobotsCore(), we need to noindex/nofollow non-public sites ourselves. if ( ! get_option( 'blog_public' ) ) { $this->attributes['noindex'] = 'noindex'; $this->attributes['nofollow'] = 'nofollow'; } $this->attributes = array_filter( (array) apply_filters( 'aioseo_robots_meta', $this->attributes ) ); return $array ? $this->attributes : implode( ', ', $this->attributes ); } /** * Sets the attributes for the current post. * * @since 4.0.0 * * @param \WP_Post|null $post The post object. * @return void */ public function post( $post = null ) { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $post = aioseo()->helpers->getPost( $post ); $metaData = aioseo()->meta->metaData->getMetaData( $post ); if ( ! empty( $metaData ) && ! $metaData->robots_default ) { $this->metaValues( $metaData ); return; } if ( $dynamicOptions->searchAppearance->postTypes->has( $post->post_type ) ) { $this->globalValues( [ 'postTypes', $post->post_type ], true ); } } /** * Returns the robots meta tag value for the current term. * * @since 4.0.6 * * @param \WP_Term|null $term The term object if any. * @return void */ public function term( $term = null ) { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $term = is_a( $term, 'WP_Term' ) ? $term : get_queried_object(); if ( $dynamicOptions->searchAppearance->taxonomies->has( $term->taxonomy ) ) { $this->globalValues( [ 'taxonomies', $term->taxonomy ], true ); return; } $this->globalValues(); } /** * Sets the attributes for the current archive. * * @since 4.0.0 * * @return void */ private function archives() { $dynamicOptions = aioseo()->dynamicOptions->noConflict(); $postType = get_queried_object(); if ( ! empty( $postType->name ) && $dynamicOptions->searchAppearance->archives->has( $postType->name ) ) { $this->globalValues( [ 'archives', $postType->name ], true ); } } /** * Sets the attributes based on the global values. * * @since 4.0.0 * * @param array $optionOrder The order in which the options need to be called to get the relevant robots meta settings. * @param boolean $isDynamicOption Whether this is for a dynamic option. * @return void */ protected function globalValues( $optionOrder = [], $isDynamicOption = false ) { $robotsMeta = []; if ( count( $optionOrder ) ) { $options = $isDynamicOption ? aioseo()->dynamicOptions->noConflict( true )->searchAppearance : aioseo()->options->noConflict()->searchAppearance; foreach ( $optionOrder as $option ) { if ( ! $options->has( $option, false ) ) { return; } $options = $options->$option; } $clonedOptions = clone $options; if ( ! $clonedOptions->show ) { $this->attributes['noindex'] = 'noindex'; } $robotsMeta = $options->advanced->robotsMeta->all(); if ( $robotsMeta['default'] ) { $robotsMeta = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->all(); } } else { $robotsMeta = aioseo()->options->searchAppearance->advanced->globalRobotsMeta->all(); } $this->attributes['max-image-preview'] = 'max-image-preview:large'; if ( $robotsMeta['default'] ) { return; } if ( $robotsMeta['noindex'] ) { $this->attributes['noindex'] = 'noindex'; } if ( $robotsMeta['nofollow'] ) { $this->attributes['nofollow'] = 'nofollow'; } if ( $robotsMeta['noarchive'] ) { $this->attributes['noarchive'] = 'noarchive'; } $noSnippet = $robotsMeta['nosnippet']; if ( $noSnippet ) { $this->attributes['nosnippet'] = 'nosnippet'; } if ( $robotsMeta['noodp'] ) { $this->attributes['noodp'] = 'noodp'; } if ( $robotsMeta['notranslate'] ) { $this->attributes['notranslate'] = 'notranslate'; } $maxSnippet = $robotsMeta['maxSnippet']; if ( ! $noSnippet && $maxSnippet && intval( $maxSnippet ) ) { $this->attributes['max-snippet'] = "max-snippet:$maxSnippet"; } $maxImagePreview = $robotsMeta['maxImagePreview']; $noImageIndex = $robotsMeta['noimageindex']; if ( ! $noImageIndex && $maxImagePreview && in_array( $maxImagePreview, [ 'none', 'standard', 'large' ], true ) ) { $this->attributes['max-image-preview'] = "max-image-preview:$maxImagePreview"; } $maxVideoPreview = $robotsMeta['maxVideoPreview']; if ( isset( $maxVideoPreview ) && is_numeric( $maxVideoPreview ) ) { $this->attributes['max-video-preview'] = "max-video-preview:$maxVideoPreview"; } // Check this last so that we can prevent max-image-preview from being output if noimageindex is enabled. if ( $noImageIndex ) { $this->attributes['max-image-preview'] = ''; $this->attributes['noimageindex'] = 'noimageindex'; } } /** * Sets the attributes from the meta data. * * @since 4.0.0 * * @param \AIOSEO\Plugin\Common\Models\Post|\AIOSEO\Plugin\Pro\Models\Term $metaData The post/term meta data. * @return void */ protected function metaValues( $metaData ) { if ( $metaData->robots_noindex || $this->isPasswordProtected() ) { $this->attributes['noindex'] = 'noindex'; } if ( $metaData->robots_nofollow ) { $this->attributes['nofollow'] = 'nofollow'; } if ( $metaData->robots_noarchive ) { $this->attributes['noarchive'] = 'noarchive'; } if ( $metaData->robots_nosnippet ) { $this->attributes['nosnippet'] = 'nosnippet'; } if ( $metaData->robots_noodp ) { $this->attributes['noodp'] = 'noodp'; } if ( $metaData->robots_notranslate ) { $this->attributes['notranslate'] = 'notranslate'; } if ( ! $metaData->robots_nosnippet && $metaData->robots_max_snippet && intval( $metaData->robots_max_snippet ) ) { $this->attributes['max-snippet'] = "max-snippet:$metaData->robots_max_snippet"; } if ( ! $metaData->robots_noimageindex && $metaData->robots_max_imagepreview && in_array( $metaData->robots_max_imagepreview, [ 'none', 'standard', 'large' ], true ) ) { $this->attributes['max-image-preview'] = "max-image-preview:$metaData->robots_max_imagepreview"; } if ( isset( $metaData->robots_max_videopreview ) && is_numeric( $metaData->robots_max_videopreview ) ) { $this->attributes['max-video-preview'] = "max-video-preview:$metaData->robots_max_videopreview"; } // Check this last so that we can prevent max-image-preview from being output if noimageindex is enabled. if ( $metaData->robots_noimageindex ) { $this->attributes['max-image-preview'] = ''; $this->attributes['noimageindex'] = 'noimageindex'; } } /** * Checks whether the current post is password protected. * * @since 4.0.0 * * @return bool Whether the post is password protected. */ private function isPasswordProtected() { $post = aioseo()->helpers->getPost(); return is_object( $post ) && $post->post_password; } }