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?