Created
September 4, 2018 17:03
-
-
Save amarilindra/53683784d9db377373852b21a7ba7019 to your computer and use it in GitHub Desktop.
Add Noindex and Nofollow meta tag to WordPress attachment pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* 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"/>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
4th September 2018, 10:34 PM - Tested on Geek Dashboard running WordPress 4.9.8 without any issues.