Hello,

First let me thank you for this module.
I'm having problems with the module metatags, my specific configuration for the instance "content" is not used when the page is rendered. I can only configure instances "global" and "global: frontpage".
For a node page, in the "metatag_page_build" function, I have metatags informations in the variable

$page ['content']['system_main']['content']['nodes'][PID ]['metatags']

but this information is never used in this function.

/**
 * Implements hook_page_build().
 */
function metatag_page_build(&$page) {
  // For some reason with Overlay enabled we get an empty $page, so just fail
  // this case.
  if (!isset($page['content'])) {
    return;
  }
  // Load the metatags render array in before any page content so that more
  // more specific meta tags in the page content can override these meta tags.
  $page['content'] = array('metatags' => array()) + $page['content'];
  if (drupal_is_front_page()) {
    $page['content']['metatags']['global:frontpage'] = metatag_metatags_view('global:frontpage', array());
  }
  elseif (!path_is_admin(current_path())) {
    // Do not output the global metatags when on an administration path.
    $page['content']['metatags']['global'] = metatag_metatags_view('global', array());
  }
}

Do you have any trouble like this ?

Comments

mmncs’s picture

I'm having the same issue.

Description, Keywords and title are not showing for content types.

poukram’s picture

I'm sorry, for me it's not a bug, I use custom templates and I solve the problem with this code :

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

I put this code in my nodes templates

See : http://drupal.org/node/1310780

marcoka’s picture

#1386320: SOLUTION: Metatags in front not working
not a bug, it seems people use custom templates and remove variables where they dont know what exactly they are doing.
does it work with the core theme? if so, your custom theme removes page vars that it should NOT remove.

dcanetma’s picture

Assigned: Unassigned » dcanetma
Status: Active » Needs work

Hi,

I'm needing to include some other ogp tags per content type on a project I'm working and faced the same issue as you.

I've managed to fix it, and I'm preparing a patch. Be patient, please.

Since I'm still not very good at managing issue queues here's the code, in case you need to fix that right away.

/**
 * Implements hook_page_build().
 */
function metatag_page_build(&$page) {
  // For some reason with Overlay enabled we get an empty $page, so just fail
  // this case.
  if (!isset($page['content'])) {
    return;
  }

  // Load the metatags render array in before any page content so that more
  // more specific meta tags in the page content can override these meta tags.
  $page['content'] = array('metatags' => array()) + $page['content'];
  if (drupal_is_front_page()) {
    $page['content']['metatags']['global:frontpage'] = metatag_metatags_view('global:frontpage', array());
  }
  elseif (!path_is_admin(current_path())) {
    // Do not output the global metatags when on an administration path.
	if (isset($page['content']['system_main']['nodes'])) {
		// Strabinarius: set the proper instance type in case it's a node we're ouputting
		$node = array_shift(array_values($page['content']['system_main']['nodes']));
		$page['content']['metatags']['global'] = metatag_metatags_view('node:' . $node['#bundle'], array());
	} else {
	    $page['content']['metatags']['global'] = metatag_metatags_view('global', array());
	}
	
  }
}
damienmckenna’s picture

Version: 7.x-1.0-alpha4 » 7.x-1.x-dev
Status: Needs work » Postponed (maintainer needs more info)

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

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.

marcelovani’s picture

damienmckenna’s picture

Status: Postponed (maintainer needs more info) » Fixed

This should work now, between the hook_entity_view change in #1363476: Panels integration - ensure meta tags work OOTB on entity pages, a matching change in the core logic in #1784896: Overriding meta tags fall back to parent default tag value and a stop-gap work-around for a missing hook for taxonomy term pages in #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view(). If you are still having a problem specifically with the front page then it is a theming issue, please get involved with / follow #1800658: Front page settings don't work on some themes (e.g. TopHit).

damienmckenna’s picture

Status: Fixed » Closed (fixed)