Hi all,

I developed a custom module for drupal 7.
In order to show the snippet description in google search results, I want to optimize this site description.
Where do I add that in my.module-file?

Many thanks for help.

Bests
Soezkan

Comments

joshi.rohit100’s picture

CaDyMaN’s picture

You can add it directly form the theme or you can put it in the html.tpl.php but this is not Drupal way.
If you want that you tag to be added on all pages you ca usehook_preprocess_html(&$variables) and put inside:


drupal_add_html_head(  [
        '#tag'        => 'meta',
        '#attributes' => [
          'name'    => 'viewport',
          'content' => 'width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no, initial-scale=1',
        ],
      ], 'viewport');

 

The hook should be in template.php from you theme . You ca used in your module to.

Or you ca use https://www.drupal.org/project/metatag for SEO

soezkan’s picture

Thanks for your replies!

Now I installed the metatags module.
If I write a description for a particular node, how do I get the content of the meta-tag-description
into here:

  $description = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'name' =>  'description',
      'content' =>  ???????????
    )
  );
  drupal_add_html_head($description, 'description');

Thanks for more help!

Bests
Soezkan

CaDyMaN’s picture

If you use metatags you do not need to do anything.
The module will add it automatically