Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 59525

changing robot do_robots function

$
0
0

Replies: 0

Question related to the function: 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 all articles
Browse latest Browse all 59525

Trending Articles