Skip to content

Instantly share code, notes, and snippets.

@bonny
Created June 13, 2013 08:42
Show Gist options
  • Save bonny/5772182 to your computer and use it in GitHub Desktop.
Save bonny/5772182 to your computer and use it in GitHub Desktop.
WordPress function that uses filter "wp_head" to add meta robots noindex for password protected pages
<?php
// if current page is password protected then kindly tell google (aka search engines) to not index the current page
function ep_noindex_password_protected_pages() {
global $wp_the_query;
if ( $wp_the_query->is_singular && post_password_required( $wp_the_query->get_queried_object ) ) {
wp_no_robots();
}
}
add_action("wp_head", "ep_noindex_password_protected_pages");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment