Skip to content

Instantly share code, notes, and snippets.

@amarilindra
Created September 4, 2018 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amarilindra/53683784d9db377373852b21a7ba7019 to your computer and use it in GitHub Desktop.
Save amarilindra/53683784d9db377373852b21a7ba7019 to your computer and use it in GitHub Desktop.
Add Noindex and Nofollow meta tag to WordPress attachment pages
/*
*
* Author: Amar Ilindra
* URL: https://www.geekdashboard.com/
*
* Add this code in your themes function.php file
*/
/*
* This function hooks into wp_head and if it is an attachment page it adds noindex, nofollow meta tag
*/
add_action('wp_head', 'ikva_noindex_attachments', 1);
if(! function_exists('ikva_noindex_attachments') ) {
function ikva_noindex_attachments() {
if(is_attachment()) {
echo '<meta name="robots" content="noindex,nofollow"/>';
}
}
}
@amarilindra
Copy link
Author

4th September 2018, 10:34 PM - Tested on Geek Dashboard running WordPress 4.9.8 without any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment