do_robots

Display the robots.txt file content.

Description

do_robots(); 

The echo content should be with usage of the permalinks or for creating the robots.txt file.


Usage

  1. if ( !function_exists( 'do_robots' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = do_robots(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function do_robots() { 
  2. header( 'Content-Type: text/plain; charset=utf-8' ); 
  3.  
  4. /** 
  5. * Fires when displaying the robots.txt file. 
  6. * @since 2.1.0 
  7. */ 
  8.  
  9. $output = "User-agent: *\n"; 
  10. $public = get_option( 'blog_public' ); 
  11. if ( '0' == $public ) { 
  12. $output .= "Disallow: /\n"; 
  13. } else { 
  14. $site_url = parse_url( site_url() ); 
  15. $path = ( !empty( $site_url['path'] ) ) ? $site_url['path'] : ''; 
  16. $output .= "Disallow: $path/wp-admin/\n"; 
  17. $output .= "Allow: $path/wp-admin/admin-ajax.php\n"; 
  18.  
  19. /** 
  20. * Filters the robots.txt output. 
  21. * @since 3.0.0 
  22. * @param string $output Robots.txt output. 
  23. * @param bool $public Whether the site is considered "public". 
  24. */ 
  25. echo apply_filters( 'robots_txt', $output, $public );