In some cases you may only want to show specific content types as embedded content in other nodes. For example slideshows or video nodes that are embedded in other nodes should be hidden for search engines. The following code snippet does exactly that.
Hide Drupal content type from being indexed by Google
function MYMODULE_node_access($node, $op, $account) {
if ($op == 'view') {
global $user;
// This checks if node is embeded in another node
// (in this case, it must be visible)
// If not embeded, these types have access denied.
if (arg(0) == 'node' && arg(1) == $node->nid) {
$hidden_types = array('CONTNET_TYPE_1','CONTNET_TYPE_2');
if ($user->uid) {
}else{
if(in_array($node->type, $hidden_types)){
return NODE_ACCESS_DENY;
}
}
}
}
// Returning nothing from this function would have the same effect.
return NODE_ACCESS_IGNORE;
}
Ad the code snippet above to one of your custom modules to hide CONTNET_TYPE_1 and CONTNET_TYPE_2 from Google search bot. Be sure to replace MYMODULE with the name of your module. Rename CONTNET_TYPE_1/2 to the content types you want to hide and feel free to add more content types to the array.
UPDATE: If you do not want to code it yourself you might want to check out the Rabbit Hole module that k_zoltan suggested in the comment section.
There is a handsome module for this job, but its name is not really expressive https://www.drupal.org/project/rabbit_hole does the same job but without coding
Thanks k_zoltan, Rabbit Hole looks like a great module I will definitely try it out.
Great article. I will be facing many of these issues as well..