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

5495

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"';

 

10 COMMENTS

  1. You made some good points there. I checked on the internet for additional information about the issue and found most people
    will go along with your views on this website. I couldn’t resist commenting.

    Well written! It’s appropriate time to make some plans
    for the future and it’s time to be happy.
    I’ve read this post and if I could I want to suggest you few interesting things or tips.
    Perhaps you can write next articles referring to this
    article. I want to read more things about it!
    http://cspan.org

  2. After I initially left a comment I seem to have clicked
    on the -Notify me when new comments are added- checkbox and
    frrom now on every time a comment is added I get four emails with the same comment.
    Perhaps there is a means you are able to remove me from that
    service? Thanks a lot!

  3. Hey! This is my first visit to your blog! We are a group of volunteers and
    starting a new initiative in a community in the same niche.

    Your blog provided us useful information to work on. You have done a marvellous job!

  4. Hmm it looks like your website ate my first comment (it was super long) so
    I guess I’ll just sum it up what I submitted and say, I’m
    thoroughly enjoying your blog. I as well am an aspiring blog writer but I’m
    still new to the whole thing. Do you have any recommendations for novice blog writers?
    I’d really appreciate it.

  5. hey there and thank you for your information – I have certainly picked up something new from right here.
    I did however expertise several technical issues using this web site, since I experienced to reload the web site many times previous to I could get it to
    load correctly. I had been wondering if your web host is OK?
    Not that I’m complaining, but sluggish loading instances times will sometimes affect your placement in google and can damage your high-quality score if ads and marketing
    with Adwords. Well I’m adding this RSS to my e-mail and could look
    out for a lot more of your respective interesting content.

    Ensure that you update this again soon.

LEAVE A REPLY

Please enter your comment!
Please enter your name here