You are here

no_index.module in Util 6.3

Same filename and directory in other branches
  1. 7 contribs/no_index/no_index.module

Prevent search indexing. Adding a robots header isn't necessarily a sure thing. It's not supported by all search engines and will not guarantee your site will be excluded. Read: http://www.sitepoint.com/why-pages-disallowed-in-robots-txt-still-appear...

File

contribs/no_index/no_index.module
View source
<?php

/**
 * @file
 * Prevent search indexing.
 * Adding a robots header isn't necessarily a sure thing. It's not supported by
 * all search engines and will not guarantee your site will be excluded.
 * Read: http://www.sitepoint.com/why-pages-disallowed-in-robots-txt-still-appear-in-google/
 */

/**
 * Implements hook_form_alter().
 * Settings to prevent search indexing.
 */
function no_index_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {

    // Settings
    case 'util_page':
      $form['no_index'] = array(
        '#type' => 'fieldset',
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
        '#title' => t('No search indexing'),
        '#description' => t('Produces site directive telling search engines to go away.'),
      );
      $form['no_index']['no_index_setting'] = array(
        '#type' => 'radios',
        '#options' => array(
          t('No'),
          t('Yes'),
        ),
        '#title' => t('No search indexing'),
        '#description' => t('Produces site directive telling search engines to go away.'),
        '#default_value' => variable_get('no_index_setting', 0),
        '#attributes' => array(
          'class' => 'container-inline',
        ),
      );
  }
}

/**
 * Implements hook_init().
 */
function no_index_init() {
  if (variable_get('no_index_setting', 0)) {
    $data = '<meta name="robots" content="noindex, nofollow" />' . "\n";
    drupal_set_html_head($data);
  }
}

/**
 * Implements hook_requirements().
 * Add note if not SE indexing.
 */
function no_index_requirements($phase) {
  $requirements = array();
  switch ($phase) {
    case 'runtime':
      if (variable_get('no_index_setting', 0)) {
        $sev = REQUIREMENT_WARNING;
        $msg = t('Search engines are being instructed to ignore this site.');
      }
      else {
        $sev = REQUIREMENT_INFO;
        $msg = t('The No_index module is enabled, but not blocking search engines.');
      }
      $requirements['no_index_status'] = array(
        'title' => 'No Index',
        'value' => $msg,
        'severity' => $sev,
      );
  }
  return $requirements;
}

Functions

Namesort descending Description
no_index_form_alter Implements hook_form_alter(). Settings to prevent search indexing.
no_index_init Implements hook_init().
no_index_requirements Implements hook_requirements(). Add note if not SE indexing.