By traceelements on
I have a bartik subtheme in Drupal 7. I can't figure out how to add meta tags to the head. It was easy to do in D6. Is there any way to to this in D7?
I have a bartik subtheme in Drupal 7. I can't figure out how to add meta tags to the head. It was easy to do in D6. Is there any way to to this in D7?
Comments
I've been trying to read
I've been trying to read Drupal 7 api, but unfortunately, I don't have php experience. Do I need to add a function to my custom template.tpl.php to print the link to the head? Can anyone help?
I see that html.tpl.php has this code:
<?php print $head; ?>So how do I add something (in my case, meta tags) to the $head?
Anyone?
Anyone?
If you don't have php
If you don't have php experience the best way would be to use module like http://drupal.org/project/nodewords http://drupal.org/project/metatags. But the problem is none of them is D7 ready yet.
There is at list a temporary solution for now: http://drupal.org/project/metatags_quick
Cheers,
Andrey
Drupal Sites Showcase. Add yours! | My Blog
Thanks, Andrey. I did see
Thanks, Andrey. I did see that module, but I don't want different meta keywords and descriptions for each page on the website. I really just want to put in a simple meta keywords and description in the head for the whole website. It just seems crazy that I can't do that without knowing php.
There's probably a way to run
There's probably a way to run a function in my template.tpl.php, but I couldn't figure out how to do it.
The solution that I found, for now, is this:
Copy html.tpl.php from modules/system to my custom theme templates folder. Then add my meta keywords and description code into the head.
I must say i'm curious about
I must say i'm curious about this too.... actualy your bypass trick didn't work for me.
open your mind open the source
express yourself, share your tools
How to add meta description and keywords to header in drupal 7
To solve your problem click the link http://sanjoy.jhenaidah.net/how-to-add-meta-description-keywords-drupal7
Thanks,
Place meta tags in head in D7
OK, without php:
Open up modules/system/html.tpl.php
I use Notepad++ to Edit
under the following line:
print $head_title;After the end title tag, put your meta information.
Hope this helps!
can you use
can you use hook_preprocess_html and modify the variables there instead?
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
Wow, Difficult.
Yes, I just noticed how difficult Drupal 7 seems to have made something that would have been so easy to do just knowing HTML. I just want to have access to my HTML code in the template file so I can place IE conditional comments in there, but that code seems to have been abstracted from the templates and comes from the database now?
And the suggestions to change it are to install extra modules?
Personally, I'd prefer the old method of being able to change the HTML, and customizing the $head variable instead to output.
What might be the rationale for having done it the other way? Now it makes simply adding an IE conditional comment cost a few hours of googling versus 10 seconds copy / paste.
that is the "drupal way", you
that is the "drupal way", you can do the html copy paste by copying html.tpl.php to your theme directory and edit the html for tag there
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
Details for Multi-site...
I put second version of html.tpl.php into the /[subtheme]/templates/ directory. (where [subtheme] is replaced by the subtheme that is enabled for my site--the place where all my customization is done)
In the customized html.tpl.php in that directory, I paste the code for the meta tag before the closing head tag (careful not to interfere with any php calls).
Then following the trusty-dusty "Clear Caches when altering templates" rule:
Administration » Configuration » Development
I refresh my page. Voila! If you do Control+U your new code should be there on the page, just above the end of the head tag.
REMEMBER: If you update your subtheme and for some reason it is not a sub-subtheme, you will likely have to re-introduce any custom code. For this reason, step zero should always be to make sure you are working on a sub to a theme or sub-sub to a base theme.
Use "#type => html_tag"
Very old post, but showed up first when searching so thought id stick a link to a good answer! - https://www.drupal.org/node/1411428
Add this to your template.php
This works as it is only for
This works as it is only for the head tag.
function YOUR_THEME_NAME_html_head_alter(&$head_elements) {
$head_elements['system_meta_ie_browser'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'X-UA-Compatible',
'content' => 'IE=edge,chrome=1',
),
'#weight' => -99999,
);
drupal_add_html_head($head_elements, 'system_meta_ie_browser');
}
I may be wrong in this but
I may be wrong in this but you can try using metatag module to add metatags in header.