0

I have a custom page which I have created using hook_menu

$items['list'] = array(
    'page callback' => 'page_callback',
    'type' => MENU_CALLBACK,
    'access arguments' => array('access content'),
);

I want to add the meta tag to head section of this page to prevent it from indexing. I have tried the following code.

function page_callback() {
  $arr = array('test1', 'test2');

  $element = array(
    '#tag' => 'meta',
    '#attributes' => array(
      'name' => 'robots',
      'content' => 'noindex',
    ),
  );
  drupal_add_html_head($element, 'test');

  // Return the list in json format.
  drupal_json_output($arr);
}

But when I inspect the page, I can't see anything in the head section of page.

When I try to return some string instead of the json, I can see that meta tag.

function page_callback() {
      $arr = array('test1', 'test2');

      $element = array(
        '#tag' => 'meta',
        '#attributes' => array(
          'name' => 'robots',
          'content' => 'noindex',
        ),
      );
      drupal_add_html_head($element, 'test');

      // Return the list in json format.
      return 'something';
    }

How can I add it to the page which outputs json?

  • OR how to prevent such page from google indexing? – Ahmad Oct 7 at 11:44
  • Meta tags are used in HTML, not JSON. – Clive Oct 7 at 12:19
  • @Clive so what should I do to prevent the list page from google indexing? – Ahmad Oct 7 at 12:37
  • Nothing in Drupal - search for “remove page from search engine index”, there are several approaches – Clive Oct 7 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.