Yoast\WP\SEO\Presentations
Indexable_Presentation::filter_robots()
Run the robots output content through the wpseo_robots
Метод класса: Indexable_Presentation{}
Хуки из метода
Возвращает
Массив
. The filtered meta robots values.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->filter_robots( $robots );
- $robots(массив) (обязательный)
- The meta robots values to filter.
Код Indexable_Presentation::filter_robots() Indexable Presentation::filter robots Yoast 21.6
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 ); $robots_new = []; foreach ( $robots_values as $value ) { $key = $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; } $robots = $robots_new; } if ( \is_bool( $robots_filtered ) && ( $robots_filtered === false ) ) { return [ 'index' => 'noindex', 'follow' => 'nofollow', ]; } if ( ! $robots_filtered ) { return []; } /** * 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 ); }