How to add meta tags programmatically to custom pages in Drupal 7

0
682

How toHow to add meta tags programmatically to custom pages in Drupal 7  Add Meta tags Programmatically to Custom Pages in Drupal 7: Its a very Easy to set  Meta Tags

  • Description,
  • Keywords,
  • title
  • what you want to add in Head Section by Using.

 

 function  hook_html_head_alter

Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().

Top Drupal SEO Modules To Boost your Website in Search Engine

Example Add Meta tags Programmatically to Custom Pages Drupal 7:

There are Two examples Given Below:

Example 1:


/**
 * Implements hook_html_head_alter().
 * @author Rizwan Siddiquee
 */
function mymodule_html_head_alter(&$head_elements) {

$head_elements['demo_descr'] = array(
 '#type' ='markup',
 '#markup' ='meta name="description" content= "How to add meta tags programmatically to custom pages in Drupal 7"',
 );
 $head_elements['demo_keyword'] = array(
 '#type' ='markup',
 '#markup' ='meta name="Keywords" content= "How to add meta tags programmatically to custom pages in Drupal 7, add meta tags programmatically to custom pages D7"',
 );

}

Example 1 Result Output:  Apply this code check source then Get result Like:-

'meta name="Keywords" content= "How to add meta tags programmatically to custom pages in Drupal 7,add meta tags programmatically to custom pages D7"';

'meta name="description" content= "How to add meta tags programmatically to custom pages in Drupal 7"';

 

OR

Example 2:


/**
 * Implements hook_html_head_alter().
 * @author Rizwan Siddiquee
 */
function college_html_head_alter(&$head_elements) {

$head_elements['demo_descr'] = array(
 '#theme' ='metatag',
 '#tag' ='meta',
 '#id' ='metatag_description',
 '#name' ='description',
 '#value' ='add meta tags programmatically to custom pages in Drupal 7',
 '#type' ='html_tag',
 );
 $head_elements['demo_keyword'] = array(
 '#theme' ='metatag',
 '#tag' ='meta',
 '#id' ='metatag_description',
 '#name' ='keywords',
 '#value' ='add meta tags programmatically to custom pages D7, How to add meta tags programmatically to custom pages in Drupal 7',
 '#type' ='html_tag',
 );

}

 

Example 2 Output: Apply code check  result Like:-


'meta name="keywords" content="add meta tags programmatically to custom pages D7, How to add meta tags programmatically to custom pages in Drupal 7"';

'meta name="description" content="add meta tags programmatically to custom pages in Drupal 7"';

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here