Title: changing robot do_robots function
Last modified: July 31, 2020

---

# changing robot do_robots function

 *  [user1105](https://wordpress.org/support/users/xabcd/)
 * (@xabcd)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/changing-robot-do_robots-function/)
 * Question related to the function: do_robots
    [https://developer.wordpress.org/reference/functions/do_robots/](https://developer.wordpress.org/reference/functions/do_robots/)
 * Not a developer but wanting to make simple change to disallow a directory called/
   temp/
 * Would that look like this? Wanted to make sure as i didn’t want to screw this
   up testing it.
 *     ```
       function do_robots() {
           header( 'Content-Type: text/plain; charset=utf-8' );
   
           /**
            * Fires when displaying the robots.txt file.
            *
            * @since 2.1.0
            */
           do_action( 'do_robotstxt' );
   
           $output = "User-agent: *\n";
           $public = get_option( 'blog_public' );
   
           $site_url = parse_url( site_url() );
           $path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
           $output  .= "Disallow: $path/temp/\n";    
           $output  .= "Disallow: $path/wp-admin/\n";
           $output  .= "Allow: $path/wp-admin/admin-ajax.php\n";
   
           /**
            * Filters the robots.txt output.
            *
            * @since 3.0.0
            *
            * @param string $output The robots.txt output.
            * @param bool   $public Whether the site is considered "public".
            */
           echo apply_filters( 'robots_txt', $output, $public );
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [Ian Sackofwits](https://wordpress.org/support/users/plantprogrammer/)
 * (@plantprogrammer)
 * [5 years, 10 months ago](https://wordpress.org/support/topic/changing-robot-do_robots-function/#post-13198382)
 * Hi, xabcd, if you’re directly modifying the WordPress core files, then I would
   recommend that you instead use a filter to do so.
 * [https://stackoverflow.com/questions/33550598/editing-robots-txt-in-wordpress-without-plugin-and-without-manual-edits](https://stackoverflow.com/questions/33550598/editing-robots-txt-in-wordpress-without-plugin-and-without-manual-edits)
   explains an easy way to modify the robots.txt file without installing any additional
   plugins.
 * The sample code that is provided (insert this into your functions.php file in
   your theme):
 *     ```
       add_filter('robots_txt', 'addToRoboText');
   
       function addToRoboText($robotext) {
           $additions = "
       # Added by filter in functions
       User-agent: NinjaBot
       Allow: /
       ";
           return $robotext . $additions;
       }
       ```
   
 * I think, the sample code should be modified as such for your situation:
 *     ```
       $additions = "Disallow: /temp/"
       ```
   
 * Based on what I see that Google recommends: [https://support.google.com/webmasters/answer/6062596?hl=en](https://support.google.com/webmasters/answer/6062596?hl=en)
 * But keep in mind you should always test code changes before implementing them
   live, so I would recommend using a service like [https://wpsandbox.net/](https://wpsandbox.net/)
   before you make changes on your site so you can prevent an error from bringing
   down your site unnecessarily.

Viewing 1 replies (of 1 total)

The topic ‘changing robot do_robots function’ is closed to new replies.

## Tags

 * [robots](https://wordpress.org/support/topic-tag/robots/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Ian Sackofwits](https://wordpress.org/support/users/plantprogrammer/)
 * Last activity: [5 years, 10 months ago](https://wordpress.org/support/topic/changing-robot-do_robots-function/#post-13198382)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
