How to block plugin generated URLs via robots.txt

Learn about how to stop Google and others from indexing plugin generated URLs.

In this article

The problem

In order to share exactly needed images with custom content like title, description or URL plugin generates special links like such one:{GENERATED_LINK}

This feature works great and does exactly what is required of it.

The problem may appear on the side of Google search and various spammers who may try to use this link generation mechanism to try to index their spam sites at your expense.

What they can try is to add their site URL inside the {GENERATED_LINK} field and they try to force Google to index it. So spam URLs can look like that:

Your Google search console one day can look like that:

Spam links inside google search console

Spam links inside google search console

The good news is that usually Google detects such links and does not index them at all. But it is better to be reinsured and also to tidy up the inside of the Google search console. How to do that we will cover in the next section.

Solution - block URLs via robots.txt

Robots.txt is a special file where you can create index rules for Google and other search engines. Default WordPress robots.txt file looks like that:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php

What we can do here is to add another Disallow rule and add inside it all URLs generated via Share This Image plugin. To create such rule we can use regular expressions:

Disallow: /wp-content/plugins*/sharer.php*

That rule will block all URLs like


Now we just need to add those new rules inside your current robots.txt file. In this article we won't cover this point in detail. One can only note that there are many different plugins for this purpose. You can choose any of them.

Or you can modify your robots.txt file with just a simple php code snippet. Here is an example of such one:

add_filter( 'robots_txt', 'my_robots_txt' );
function my_robots_txt( $output ) {
    $site_url = parse_url( site_url() );
    $path     = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : '';
    $replace  = "Disallow: $path/wp-admin/n";
    $output = str_replace( $replace, $replace . "Disallow: /wp-content/plugins*/sharer.php*n", $output );
    return $output;

You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.

After this modification your robots.txt file must look like that:

User-agent: *
Disallow: /wp-admin/
Disallow: /wp-content/plugins*/sharer.php*
Allow: /wp-admin/admin-ajax.php

Note: you can use this Google tool to text your robots.txt file and how it works with different URLs.