Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Add Noindex and Nofollow meta tag to WordPress attachment pages
* Author: Amar Ilindra
* URL:
* 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"/>';

This comment has been minimized.

Copy link
Owner Author

amarilindra commented Sep 4, 2018

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
You can’t perform that action at this time.