Changeset 50370
- Timestamp:
- 02/16/2021 11:36:44 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/default-filters.php
r50131 r50370 239 239 // Robots filters. 240 240 add_filter( 'wp_robots', 'wp_robots_noindex' ); 241 add_filter( 'wp_robots', 'wp_robots_noindex_search' ); 241 242 add_filter( 'wp_robots', 'wp_robots_max_image_preview_large' ); 242 243 -
trunk/src/wp-includes/robots-template.php
r50078 r50370 89 89 90 90 /** 91 * Adds noindex to the robots meta tag if a search is being performed. 92 * 93 * If a search is being performed then noindex will be output to 94 * tell web robots not to index the page content. Add this to the 95 * {@see 'wp_robots'} filter. 96 * 97 * Typical usage is as a {@see 'wp_robots'} callback: 98 * 99 * add_filter( 'wp_robots', 'wp_robots_noindex_search' ); 100 * 101 * @since 5.7.0 102 * @see wp_robots_no_robots() 103 * 104 * @param array $robots Associative array of robots directives. 105 * @return array Filtered robots directives. 106 */ 107 function wp_robots_noindex_search( array $robots ) { 108 if ( is_search() ) { 109 return wp_robots_no_robots( $robots ); 110 } 111 112 return $robots; 113 } 114 115 /** 91 116 * Adds noindex to the robots meta tag. 92 117 * -
trunk/tests/phpunit/tests/robots.php
r50284 r50370 177 177 } 178 178 179 /** 180 * @ticket 52457 181 */ 182 public function test_wp_robots_search_page() { 183 add_filter( 'wp_robots', 'wp_robots_noindex_search' ); 184 $this->go_to( home_url( '?s=ticket+52457+core.trac.wordpress.org' ) ); 185 186 $output = get_echo( 'wp_robots' ); 187 $this->assertContains( 'noindex', $output ); 188 } 189 190 /** 191 * @ticket 52457 192 */ 193 public function test_wp_robots_non_search_page() { 194 add_filter( 'wp_robots', 'wp_robots_noindex_search' ); 195 $this->go_to( home_url() ); 196 197 $output = get_echo( 'wp_robots' ); 198 $this->assertNotContains( 'noindex', $output ); 199 } 200 179 201 public function add_noindex_directive( array $robots ) { 180 202 $robots['noindex'] = true;
Note: See TracChangeset
for help on using the changeset viewer.