Exclude Page or Post from WordPress and Google Search
Sometimes I am asked by clients to quickly design and create new pages on a live site. In these cases I generally create a password protected page and provide my client the link and password for review of the new page before pushing it live.
To ensure that there is no possibility that the page is seen I also add a great little utility plug-in I discovered called Search Exclude. The plug-in excludes any Page, Post, or Custom Post Type entry from any front end WordPress database searches.
In order to extend the plug-in’s functionality to include noindex and nofollow meta instructions you need to add the following code to your theme’s functions.php file. This will ensure search engine’s like Google don’t find the content as well.
function add_meta_for_search_excluded()
{
global $post;
if (false !== array_search($post->ID, get_option('sep_exclude', array()))) {
echo '<meta name="robots" content="noindex,nofollow" />', "\n";
}
}
add_action('wp_head', 'add_meta_for_search_excluded');
