Adding a noindex meta tag to your WordPress login pageOver half of a million – that’s the number of WordPress login pages currently indexed by Google. Even in the relatively few situations where WordPress is used as a multi-author blogging platform, there is often no need (or even desire on the part of site owners) for wp-login.php to be indexed by search engines.

Anyone remotely interested in Search Engine Optimization is aware that having content that is shared among other sites isn’t a good idea – Google in particular is becoming increasingly aggressive in the fight against duplicate content. Now, we’d be fooling ourselves if we thought search engines aren’t smart enough to tell the difference between pages that serve a strictly functional purpose, like wp-login.php, and pages that are being promoted as a Web site’s content; that still doesn’t make it a good idea to leave these straggling pages in the indices.

Most of us rarely have a need to mess with any core files, so seeking a plugin to patch this problem is only natural. However, in this instance the fix is incredibly easy, so uninstall that plugin and open your favorite IDE and FTP client.

Step-by-Step Guide

  1. Download wp-login.php from the root directory of your WordPress installation.
  2. Open wp-login.php and save a copy as wp-login-backup.php so that we have the old file in case something goes wrong, or you decide to revert the change in the future.
  3. Find the beginning of the page’s HTML markup, it’ll be around line 60 and will look something like this:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    <head>
    	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    	<title><?php bloginfo('name'); ?> › <?php echo $title; ?></title>
  4. Between the <meta> Content-Type tag and the <title> tag, create a new line.
  5. On the new line, insert your noindex,nofollow <meta>tag:
    <meta name="robots" content="noindex,nofollow" />
  6. That part of your wp-login.php file should now look something like:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    <head>
    	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    	<meta name="robots" content="noindex,nofollow" />
    	<title><?php bloginfo('name'); ?> › <?php echo $title; ?></title>
  7. Save the changes you’ve made.
  8. Upload the wp-login.php file we’ve just edited to your server, overwriting the original file.

That should be it, but just to be sure you did everything correctly, navigate to wp-login.php on your site. If you’re automatically logged in, you’ll need to sign out so you can view the login form. Once the page has loaded, view the page’s source code.

If everything looks right then you’re done. If you’re having any issues, walk through the steps above again and find out where the mistake was made. If all else fails, simply revert back to the backup file we created.

Conclusion

Since wp-login.php doesn’t use any templates, editing it is fairly straight forward – all of the markup is contained within the file. Note that you may have to apply this simple change after each upgrade, but it’s much easier and more reliable than depending on a plugin that you’ll also have to upgrade if wp-login.php changes.

If you have any questions, feel free to comment below and I can help you figure things out.

POSTED BY
POSTED IN Tutorials
DISCUSSION 2 Comments
TAGS

,

2 Responses to : How-to Add Meta NoIndex to wp-login.php in WordPress

  1. Amit Sajinidad says:

    Great job, Ive been looking to get my wordpress login out of the search engines forever, this should do it +1

  2. PluncNenimilm says:

    Nice, I noticed that WordPress already had a noindex meta tag in wp-login, but for some reason it never works and displays when I view source. This fix worked for me