How to deal with them Spam Search Backlinks

January 24, 2021

Anne Allen

Have you seen a sudden rise in spammy backlinks to your site

https://mydomain.com/?s=%F0%9F%92%BD%E2%A0%A9%F0%9F%9F%A0%20www.FastPharmacy.store%20%F0%9F%9F%A0%E2%A0%A9%F0%9F%92%BD%20Acheter%20cialis%20en%20pharmacie

If you have and you can’t figure out why or what to do then follow this list of actions

  1. Is your Error logging turned on
    define('WP_DEBUG', true);

    This can be exploited by spammers to force and error message to show their payload of links to dubious sites.
    Fix: Turn it off!. Check your wp-config.php and replace the above line with
    define('WP_DEBUG', False);
  2. Change your search query parameter so that these links just default to your domain, and don’t show a search page
    add_filter('init', function(){
        global $wp;
    
        $wp->add_query_var( 'search_query' );
        $wp->remove_query_var( 's' );
    } );
    
    
    add_filter( 'request', function( $request ){
        if ( isset( $_REQUEST['search_query'] ) ){
            $request['s'] = $_REQUEST['search_query'];
        }
    
        return $request;
    } );
  3. Replace your search form to ensure that the new parameter is use
        <form class="search-form" method="get" action="https://www.mydomain.com/" role="search"><label class="search-form-label screen-reader-text" for="searchform-1">Search this website</label><input class="search-form-input" type="search" name="search_query" id="searchform-1" value="" placeholder="Search this website"><input class="search-form-submit" type="submit" value="Search"><meta content="https://www.mydomain.com/?search_query={search_query}"></form>

Once you have done this, the spam links should start to fade away as anyone clicking on them just ends up on your home page

The nature of these links, and the pages they are coming from means that Google will mostly ignore them anyway, and they will fade away quite quickly

Anne Allen

About the author

Hi, I’m Anne Allen. I’ve spent the last 15 years living and breathing WordPress. I’m passionate about helping business owners demystify their websites—whether that means keeping your site secure with proper maintenance, setting up complex Gravity Forms, or ensuring your content is accessible through ADA compliance. Let’s make your site work for you.