Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Metatags works perfectly on the standard taxonomy template. But when I overwrite it (for example taxonomy-term-3.tpl.php) The metatags module doesn't seem to work at all. My description tags do not appear, and the title defaults back to the standard D7 page title.
This goes for any templates I have overwritten. I have not changed any code in the template itself, simply created the new template and refreshed the theme registry.
Any ideas?
Comments
Comment #1
Fleshgrinder CreditAttribution: Fleshgrinder commentedSame here, doesn't work with any of my custom templates.
Comment #2
Fleshgrinder CreditAttribution: Fleshgrinder commentedChanged this to critical as the whole module is unusable for custom Drupal installations. Any help is welcome in finding out why the module always falls back to the global settings.
To reproduce:
- Install Drupal
- Install the module
- Create a custom template (for taxonomy, a content type, ... doesn't matter)
- Set up custom meta tag handling from within the Metatag UI for that custom template
- Now load a page and have a look at the meta tags
I created a content type Custom (Machine name: custom) and created a node--custom.tpl.php with some custom code. Drupal is working just fine and everything is rendered correctly but the meta tags aren't showing up as I have configured them.
Comment #3
jriddiough@gmail.com CreditAttribution: jriddiough@gmail.com commentedVerified.. I am having this same problem. It is still rendering the standard drupal headers.
Comment #4
jriddiough@gmail.com CreditAttribution: jriddiough@gmail.com commentedIt does work on the front page, however.
Comment #5
Dave ReidDo your custom templates use
render($content['metatags']);
at all?Comment #6
jriddiough@gmail.com CreditAttribution: jriddiough@gmail.com commentedI don't think so.. I've looked through my template for that - don't see it.
Comment #7
jriddiough@gmail.com CreditAttribution: jriddiough@gmail.com commentedAdded it to the top of my node override, and now see it!! My confusion started from the fact that I did see auto-generated metatags before. Thanks!
Comment #8
dimon00 CreditAttribution: dimon00 commentedI believe I'm having the same issue.
But my templates (node types) are modified via pages/panels.
Metatags are rendered but they are the ones inherited and not the ones defined for the node types.
Comment #9
desmond_liang CreditAttribution: desmond_liang commentedI added
render($content['metatags']);
on custom templates and it works. Nicely done. Thank you very much.Comment #10
dimon00 CreditAttribution: dimon00 commentedTwo problem for me:
1. I don't have $content since I'm showing only some field using panel,
I should be able to solve it by using something like:
$noderefnode = node_load($nodeid);
render($noderefnode->metatags);
So my second point:
2. Where is the custom template for a node using panels (without editing a tpl.php file directly)?
Where do I have to place the render function?
Comment #11
13rac1 CreditAttribution: 13rac1 commenteddimon00 refer to #1151938: Panels integration - meta discussion
Comment #12
ytsurk#5 does it. (without panels ..), think also of
print render($page['content']['metatags']);
;)
Comment #13
phenaproximaI'd like to say that I was having this exact problem on a client site (we're using Drupal 7.8 and Metatags 7.x-1.0-alpha3) and adding render($content['metatags']) to my custom taxonomy-term.tpl.php solved it.
Comment #14
FiNeX CreditAttribution: FiNeX commentedIn reply of comment #5: after reading this thread I've discovered the needing of
render($content['metatags']);
.I suggest to add that workaround on the main Meta Tags page or on a README.txt which could be shipped inside the module package.
Thanks :-)
Comment #15
tecjam CreditAttribution: tecjam commentedI am having the same problem. However, I don't quite understand the render($content) part.
The headers are outputted in the html.tpl.php file, which doesn't have the $content variable defined.
You can see what variables are available in teh html.tpl.php file (/modules/system/html.tpl.php):
So obviously the notice displayed will be:
Notice: Undefined variable: content in include()
Now if I try something like
dsm($page);
I have the template file returned, no array of variables.
I have a lot of overridden templates, but html.tpl.php is not one of them. I have many customized page.tpl.php and node.tpl.php files.
I have also set the front page to be a page - node 1 - in my case.
Comment #16
cduwe CreditAttribution: cduwe commented+1 on not understanding why the solution works. However, stuffing the render statement into the page template override correctly renders the variable in the
<head>
of the page.Comment #17
Agileware CreditAttribution: Agileware commentedThe solution in our case was:
The Taxonomy field *must* be displayed on the Content Type for Meta Data, Keyword to work. If Taxonomy field is hidden, then Meta Data, Keyword is *empty*.
See https://skitch.com/jusfreeman/8gqyb/content-type
Comment #18
rootical CreditAttribution: rootical commentedrender($page['content']);
Rendering [age`s content fixed the problem for me though the line given in #9 did nothing. I`ve used overridden pages for taxonomy terms.Comment #19
gilzero CreditAttribution: gilzero commentedMarked.
Comment #20
cblanglois CreditAttribution: cblanglois commentedHello,
I'm new to Drupal and I face almost the same problem---the meta tags don't work in my other pages EXCEPT the front page, which has the Global Setting. Does this script below solve the problem? If so, where do I put it please?
Comment #21
FiNeX CreditAttribution: FiNeX commented@cblangois: you have to put that code in node templates (like node.tpl.php)
Comment #22
liminu CreditAttribution: liminu commentedI try to add
but not works, any suggestion?
Comment #23
gilzero CreditAttribution: gilzero commentedshould be
render($page['content']['metatages'];
Comment #24
cblanglois CreditAttribution: cblanglois commentedThanks a lot, Finex.
Comment #25
cblanglois CreditAttribution: cblanglois commentedOkay, I put in the script
in node.tpl.php
but it's still not working. Can someone please give me a step-by-step starting with configuring the meta tags defaults under CONFIGURATION / SEARCH AND METADATA / METATAGS
I'm using Drupal 7.7.
Sigh.
Comment #26
FiNeX CreditAttribution: FiNeX commentedThe correct code is:
Be careful, you've to put it on each node template. If you have overridden both "Article" content type and "Page" you will have to add the code to: node--article.tpl.php and node--page.tpl.php.
:-)
Comment #27
frankcarey CreditAttribution: frankcarey commentedThis seems like a very odd way of getting these things overridden. @Dave Reid, Can you explain why this is done this way? Why not use a preprocess function directly? looking at the render array, I see it puts everything into [#attached] , I'm not familiar with that property, but it looks like it ends up firing a function that ends up adding items to the head?
Comment #28
Zahak CreditAttribution: Zahak commentedThanks, it's working here to. Thanks!
Updating version, and category.
Can't understand how this is considered as a "support request". This can't be how this is meant to implemented? (Then why not write some documentation telling people how to install the module on custom templates?)
Comment #29
sircosta CreditAttribution: sircosta commentedNot working for taxonomy/term/tid path.
I've tried to create taxonomy-term.tpl.php with this code:
and put it in the theme folder just to try to customize de default taxonomy/term/% view and obtain the description and keywords meta tags without success.
I don't know what I'm doing wrong. I've cleared cache too.
Any suggestion? Thanks!
Comment #30
mwbyrd CreditAttribution: mwbyrd commentedI've been having the same problem. Can't get any new custom metatags to show up. I'm using Meta Tags Quick 7.x-2.4+7-dev. I tried clearing cache, adding render ($content[metatags] to the content header in the template file. Out of ideas, I tried running Cron and received the following error. I'm not a programmer so maybe this is the issue?
Warning: Invalid argument supplied for foreach() in _metatags_quick_add_head() (line 491 of C:\xampp\htdocs\****\modules\metatags_quick\metatags_quick.module).
I looks like the is an error in the module when it comes to adding custom metatags to the header?
Comment #31
Oceanman CreditAttribution: Oceanman commentedmwbyrd, this is not the correct issue queue for Meta Tags Quick . This is for Meta Tags.
Comment #32
maximer CreditAttribution: maximer commentedHi,
this bug is really annoying. I hope it will be fixed in the next release.
Has anyone a patch to solve this problem?
Comment #33
wellingtonwong CreditAttribution: wellingtonwong commentedI've also ran into this problem, the fix for me was to render the page content itself.
or
Hope this helps.
Comment #34
DamienMcKennaRather than hacking away trying to get this working, and ultimately building work-arounds for an existing work-around in Metatag, the output logic has been re-written thanks to jenlampton and I'm hoping it works better now. Please try the latest -dev release and please let me know if it works as-is, and re-open the issue if it's still not working.
That said, please be aware that right now it doesn't let you override tags for taxonomy term pages due to a core bug, please keep an eye on #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view() for further updates.
Comment #35
DamienMcKennaComment #36
DamienMcKennaComment #37
maomaohuhu CreditAttribution: maomaohuhu commented7.x-1.x-dev works for me, thanks a lot ! ( it also fixed the issue I had with Omega theme )
Comment #38
DamienMcKennaRelated and honestly a higher priority: #1708718: Ensure Meta tags work OOTB with Drupal core
I'm going to fix that and then see how to resolve this issue.
Comment #39
sircosta CreditAttribution: sircosta commented+1 DamienMcKenna
Thanks for your effort! ;)
Comment #40
standingtall CreditAttribution: standingtall commentedThis is a major issue and brings the whole Drupal SEO to its knees unless fixed..
Not sure what can be done but would appreciate if developers can fix this as this issue makes Meta Tag module virtually useless for overridden themes.
Thanks
Comment #41
DamienMcKenna@standingtall: Have you tested alpha8?
Comment #42
DamienMcKennaA fix from #1748388: metatags not showing on frontpage with a view may also have helped this, so could someone who has been having problems with the module please try the current -dev version, thanks.
Comment #43
leanne9 CreditAttribution: leanne9 commentedI am using meta tags -alpha8 and I still could not get this to work properly without adding the
to every overridden template involved (not sure why so many of my site's templates were overridden but that's what happens when people dash around on the site!)
Comment #44
DamienMcKennaTaxonomy term pages were not working until recently due to a core bug (see: #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view()). If the problem persists with the front page please follow #1800658: Front page settings don't work on some themes (e.g. TopHit).
Comment #45
DamienMcKennaWe need a definitive answer for what must be present in the output templates in order to ensure that the Metatag output is displayed correctly, and what changes to avoid making in template files.
Comment #46
Sam152 CreditAttribution: Sam152 commentedIf you would like to apply this fix to all your templates without having to add code into each one, you can use the following in your template.php file:
Comment #47
charlie-s CreditAttribution: charlie-s commentedI've thrown
into template_preprocess_html() to get the metatags printing, but this does not include the title tag that should be provided.
Comment #48
funkym CreditAttribution: funkym commentedThe following code worked for me when using Omega:
Comment #49
Tran CreditAttribution: Tran commentedWhere did you put that code?
Comment #50
DamienMcKennaAn item has been added to the README.txt file that should cover this, please see #1386320: SOLUTION: Metatags in front not working.
Comment #51
DamienMcKennaNow that Metatag v7.x-1.0-beta5 is out am closing this to keep the issue queue clean.
Comment #52
mesh CreditAttribution: mesh commentedAfter looking at the comments on this page and tinkering around with the custom theme I figured out that Metatag output is tied-up with $page['content'], and thus requires
<?php print render($page['content']) ?>
to be present in page.tpl.php, even if there is no such region declared in your custom theme.Comment #53
tuananhvn80 CreditAttribution: tuananhvn80 commented#52 - it work for me, but i don't understand
Comment #54
tomas.teicher CreditAttribution: tomas.teicher commentedI think there is still problem as described by tecjam #15
Meta tags should be generated in html.tpl.php template file, not page.tpl.php. But there is no variable like $page['content'] in html.tpl.php
On html.tpl.php documentation page is mentioned in variables list:
$head: Markup for the HEAD section (including meta tags, keyword tags, and so on).
I think the clearest way to generate meta tags should be this variable
Comment #55
robbin.zhao CreditAttribution: robbin.zhao commentedI agree with @tomas.teicher
Comment #56
nimbuz77 CreditAttribution: nimbuz77 commentedI'm using Zen subtheme, I tryied all the code snipet but without any luck.
Someone solved that?
Comment #57
DamienMcKenna@nimbuz77: Try switching to another theme, see if the tags start showing.
Comment #58
nimbuz77 CreditAttribution: nimbuz77 commentedWith Bartik they are present.
I'm using a custom sub theme from Zen
Also I just noticed that they aren't shown only on the front page.
I have a custom page--front.tpl.php but not a custom html.tpl.php file for the front page.
Comment #59
Pascal.s CreditAttribution: Pascal.s commentedI'm using Zen subtheme as well and it works on all pages except front page. So for now, my workaround is to override global:frontpage in admin/config/search/metatags
I'd prefer to manage metatags directly in the page so i'm still looking for a final fix