0

I want to be able to use the meta tag module for everything my site, but currently I have no idea how to add meta tags to custom pages. For example, I have this page:

function mymodule_menu() 
{ 
    $items = array();
    $items['home'] = array(
      'title' => 'Home',
      'page callback' => 'mymodule_home_page',
      'access callback' => TRUE,
    );
    return $items;
}

function mymodule()
{
    $o = '';
    $o .= 'hello world';
    return $o;
}

Such a page doesn't get meta tags as it is a custom page. What is the best way to get meta tags on the page in this case? Or what is wrong with my strategy?

1

You can do this manually by using drupal_add_html_head(); in your menu's callback function

<?php

function mymodule_home_page() {

  $element = array(
    '#tag' => 'meta', 
    '#attributes' => array( 
      'name' => 'custom meta info', 
      'content' => 'test content',
      'attributes' => 'D7',
    ),
  );
  drupal_add_html_head($element, 'Test');

  return 'hello';
} 
?>

or some modules will allow you to add custom paths.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.