Support » Plugin: Blackhole for Bad Bots » Adding Blackhole Rule to Generated robots.txt file

  • Resolved Pat K

    (@blackcapdesign)


    This looks like a great way to block pesky and malicious bots – thanks for sharing your plugin!

    I have a few other plugins that dynamically add code to the generated robots.txt file and I didn’t see any instructions for adding the required blackhole rule dynamically (only instructions for creating the file manually). So for anyone wishing to add the blackhole rule dynamically, adding this code snippet to the functions.php file in the site’s child theme worked for me:

    // Add Blackhole for Bad Bots Rule to generated robots.txt file 
    add_filter('robots_txt', 'machine_robots', 10, 2 );
    function machine_robots( $output, $public ) {
      $output .= "Disallow: /?blackhole";
      return $output;
    }

    I will post a follow up if this causes any problems…

    pk

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.