Puddinq.com sharing knowledge

Add things to robots.txt

Add things to robots.txt

In WordPresss there is a hook to add stuff to the robots.txt searchengines use to determine what to search thrue. In the following example we add the sitemap to robots.txt to make sure searchengines will find it.

add_filter( 'robots_txt', 'puddinq_robots_txt_function', 10, 2 );
function puddinq_robots_txt_function( $robots_txt = '', $public = '' ) {
    /**
     * Don't do anything if the blog isn't public
     */
    if ( '0' == $public )
        return $robots_txt;
 
    $domain = $_SERVER['HTTP_HOST'];
 
 
 
    // .= adds extra's to a string, in this case $my_output
    $robots_txt .= 'http://' . $domain . '/sitemap_index.xml';
 
    return $robots_txt;
}