Skip to content

Instantly share code, notes, and snippets.

@annalinneajohansson
Last active December 30, 2015 09:29
Show Gist options
  • Save annalinneajohansson/7809276 to your computer and use it in GitHub Desktop.
Save annalinneajohansson/7809276 to your computer and use it in GitHub Desktop.
Do not index attachment pages in WordPress
<?php
/*
Plugin Name: Hippies attachments noindex
Plugin URI:
Description: Do not index attachment pages and set default image link type to "none" on plugin activation.
Version: 1
Author: Hippies
Author URI: http://hippies.se/
*/
add_action( 'wp_head', 'hip_attachments_noindex_wp_head' );
function hip_attachments_noindex_wp_head() {
if( is_attachment() ) {
echo '<meta name="robots" content="noindex, follow">';
}
}
function hip_attachments_noindex_activate() {
update_option( 'image_default_link_type', 'none' );
}
register_activation_hook( __FILE__, 'hip_attachments_noindex_activate' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment