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

Fleshgrinder’s picture

Same here, doesn't work with any of my custom templates.

Fleshgrinder’s picture

Priority: Normal » Critical

Changed 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.

jriddiough@gmail.com’s picture

Version: 7.x-1.x-dev »
Category: support » bug
Priority: Normal » Critical
Issue tags: -D7 stable release blocker

Verified.. I am having this same problem. It is still rendering the standard drupal headers.

jriddiough@gmail.com’s picture

It does work on the front page, however.

Dave Reid’s picture

Category: bug » support
Priority: Critical » Normal

Do your custom templates use render($content['metatags']); at all?

jriddiough@gmail.com’s picture

I don't think so.. I've looked through my template for that - don't see it.

jriddiough@gmail.com’s picture

Added 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!

dimon00’s picture

I 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.

desmond_liang’s picture

I added render($content['metatags']); on custom templates and it works. Nicely done. Thank you very much.

dimon00’s picture

Two 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?

13rac1’s picture

ytsurk’s picture

Version: » 7.x-1.0-alpha3

#5 does it. (without panels ..), think also of

print render($page['content']['metatags']);

;)

phenaproxima’s picture

I'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.

FiNeX’s picture

In 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 :-)

tecjam’s picture

I 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):

 * Variables:
 * - $css: An array of CSS files for the current page.
 * - $language: (object) The language the site is being displayed in.
 *   $language->language contains its textual representation.
 *   $language->dir contains the language direction. It will either be 'ltr' or 'rtl'.
 * - $rdf_namespaces: All the RDF namespace prefixes used in the HTML document.
 * - $grddl_profile: A GRDDL profile allowing agents to extract the RDF data.
 * - $head_title: A modified version of the page title, for use in the TITLE
 *   tag.
 * - $head_title_array: (array) An associative array containing the string parts
 *   that were used to generate the $head_title variable, already prepared to be
 *   output as TITLE tag. The key/value pairs may contain one or more of the
 *   following, depending on conditions:
 *   - title: The title of the current page, if any.
 *   - name: The name of the site.
 *   - slogan: The slogan of the site, if any, and if there is no title.
 * - $head: Markup for the HEAD section (including meta tags, keyword tags, and
 *   so on).
 * - $styles: Style tags necessary to import all CSS files for the page.
 * - $scripts: Script tags necessary to load the JavaScript files and settings
 *   for the page.
 * - $page_top: Initial markup from any modules that have altered the
 *   page. This variable should always be output first, before all other dynamic
 *   content.
 * - $page: The rendered page content.
 * - $page_bottom: Final closing markup from any modules that have altered the
 *   page. This variable should always be output last, after all other dynamic
 *   content.
 * - $classes String of classes that can be used to style contextually through
 *   CSS.

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.

cduwe’s picture

+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.

Agileware’s picture

The 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

rootical’s picture

render($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.

gilzero’s picture

Marked.

cblanglois’s picture

Hello,

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?

 render($content['metatags']); 
FiNeX’s picture

@cblangois: you have to put that code in node templates (like node.tpl.php)

liminu’s picture

I try to add

 render($content['metatags']); 

but not works, any suggestion?

gilzero’s picture

should be

render($page['content']['metatages'];

cblanglois’s picture

Thanks a lot, Finex.

cblanglois’s picture

Okay, I put in the script

 render($page['content']['metatags']; 

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.

FiNeX’s picture

The correct code is:

render($content['metatags']);

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.

:-)

frankcarey’s picture

This 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?

Zahak’s picture

Version: 7.x-1.0-alpha3 » 7.x-1.0-alpha6
Category: support » bug

Thanks, 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?)

sircosta’s picture

Not working for taxonomy/term/tid path.

I've tried to create taxonomy-term.tpl.php with this code:

<?php
render($content['metatags']);
?>

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!

mwbyrd’s picture

I'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?

Oceanman’s picture

mwbyrd, this is not the correct issue queue for Meta Tags Quick . This is for Meta Tags.

maximer’s picture

Hi,

this bug is really annoying. I hope it will be fixed in the next release.
Has anyone a patch to solve this problem?

wellingtonwong’s picture

I've also ran into this problem, the fix for me was to render the page content itself.

<?php
 render($page['content']);
?>

or

<?php
 render($page['content']['system_main']);
?>

Hope this helps.

DamienMcKenna’s picture

Rather 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.

DamienMcKenna’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +D7 stable release blocker
DamienMcKenna’s picture

Version: 7.x-1.0-alpha6 » 7.x-1.x-dev
maomaohuhu’s picture

7.x-1.x-dev works for me, thanks a lot ! ( it also fixed the issue I had with Omega theme )

DamienMcKenna’s picture

Related 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.

sircosta’s picture

+1 DamienMcKenna

Thanks for your effort! ;)

standingtall’s picture

Status: Postponed (maintainer needs more info) » Active

This 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

DamienMcKenna’s picture

@standingtall: Have you tested alpha8?

DamienMcKenna’s picture

Status: Active » Postponed

A 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.

leanne9’s picture

I am using meta tags -alpha8 and I still could not get this to work properly without adding the

render($page['content']);

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!)

DamienMcKenna’s picture

Taxonomy 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).

DamienMcKenna’s picture

Category: bug » support
Status: Postponed » Active

We 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.

Sam152’s picture

If 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:

/**
 * Ensure meta-tags module gets fired.
 */
function THEME_preprocess_node(&$vars){
	render($vars['content']['metatags']);
}
charlie-s’s picture

I've thrown

<?php
render($vars['page']['content']['metatags']);
?>

into template_preprocess_html() to get the metatags printing, but this does not include the title tag that should be provided.

funkym’s picture

The following code worked for me when using Omega:

/**
 * Implements hook_preprocess_html().
 */
function THEME_preprocess_html(&$vars) {
  // Ensure metatag module gets fired.
  render($vars['page']['content']['content']['content']['metatags']);
}
Tran’s picture

Where did you put that code?

DamienMcKenna’s picture

Version: » 7.x-1.x-dev
Category: bug » support
Priority: Critical » Normal
Status: Active » Fixed
Issue tags: +D7 stable release blocker

An item has been added to the README.txt file that should cover this, please see #1386320: SOLUTION: Metatags in front not working.

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

Now that Metatag v7.x-1.0-beta5 is out am closing this to keep the issue queue clean.

mesh’s picture

After 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.

tuananhvn80’s picture

#52 - it work for me, but i don't understand

tomas.teicher’s picture

I 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

robbin.zhao’s picture

I agree with @tomas.teicher

nimbuz77’s picture

I'm using Zen subtheme, I tryied all the code snipet but without any luck.
Someone solved that?

DamienMcKenna’s picture

@nimbuz77: Try switching to another theme, see if the tags start showing.

nimbuz77’s picture

With 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.

Pascal.s’s picture

Issue summary: View changes
Issue tags: -

I'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