I've been scratching my head quite some time on this issue, here is the situation I'm facing:

I have a content type that I want to integrate with Facebook Open Graph. I could create and customize the tags I needed for that task (I have a facebook app declaring new objects). And I simply override the value of the og:type tag (you can also try with the keywords tag it's the same behavior by the way) with my custom value on my custom content type.

When I open a node of that content type I always have the default (Global) tag value for both keywords and og:type. I decided to check the documentation (found none), so out of curiosity I dove into the code.

From what I saw (don't have a broad overview of the module yet), the order in which the tag groups are being stored in the $page variable (metatag_page_build(&$page)) is impacting the rendering of the tags (through drupal_add_html_head).

Custom tags are being stored before the default tag values in the metatags array.

A simple change solved my problem. Instead of having this code:

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' => metatag_page_get_metatags()) + $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());
  }

}

I now have that

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;
  }

  $page['content']['metatags'] = array();

  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());
  }
  
   // 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']['metatags'] += metatag_page_get_metatags();

}

I'm not sure it's the clean way to go though, this is why I'm posting those changes here... Please let me know if it's the clean way to go (if so, feel free to roll it inside the next version of the module) otherwise do tell me what I'm missing so I can easily perform updates of the module in the future.

Cheers,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcelovani’s picture

jmart’s picture

I think the problem is with the not operator:

 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());
  }

When I take out the ! and change !path_is_admin(current_path()) to path_is_admin(current_path()), it works:

So the final is

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' => metatag_page_get_metatags()) + $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());
  }
}

That's because

marcelovani’s picture

Default metatags are being loaded instead of metatags saved on the entity.
I have created a patch for the dev version.

marcelovani’s picture

That still overrides the array, this new patch will fix it by merging the arrays i.e. global and content

marcelovani’s picture

Status: Active » Needs review
marcelovani’s picture

Re-done the patch to fix an error when trying to merge an empty array

Status: Needs review » Needs work

The last submitted patch, overriding-metatags-fall-back-parent-default-value-1784896.patch, failed testing.

marcelovani’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, overriding-metatags-fall-back-parent-default-value-1784896.patch, failed testing.

marcelovani’s picture

Test if failing for some reason, I am submitting again

marcelovani’s picture

Status: Needs work » Needs review
couturier’s picture

Status: Needs review » Reviewed & tested by the community
DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs work
FileSize
1.5 KB

I think this could be reduced even further.

The key question is - given that loading meta tags will automatically include the global settings via metatag_config_load_with_defaults(), what is the reason to load the global settings again in metatag_page_build()?

DamienMcKenna’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, metatag-n1784896-13.patch, failed testing.

DamienMcKenna’s picture

Version: 7.x-1.0-alpha8 » 7.x-1.x-dev
Status: Needs work » Reviewed & tested by the community

Lets try this again.

DamienMcKenna’s picture

#13: metatag-n1784896-13.patch queued for re-testing.

couturier’s picture

kbasarab’s picture

Can confirm #13 works as expected and began showing Meta Tags on page.

My issue:
No meta tags were loading on page at all.

Using Omega theme (3.x) and display suite (v7.x-1.5) modules.

I upgraded Meta Tag to dev from Alpha 8 first and saw no change. Applied patch in #13 and tags began coming from defaults.

DamienMcKenna’s picture

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Fixed

Committed! Thanks for the work identifying this problem, marcelovani.

hass’s picture

I have a problem that Title is not set on Frontpage.

I have overriden Global: Front page with [site:name] (Foo, Bar), but the customized title is still shown as My site name | what is also not [current-page:title] | [site:name].

Is this the patch for this issue?

hass’s picture

Disabled page title module and now metatags works as expected.

couturier’s picture

[Update: this is the wrong link. See comment #29 below.)

Aha! I thought that Page Title and Meta Tags modules would conflict if you tried to enable them both. That's why I commented on this issue to request that Meta Tags add some user documentation for one of the last major features that Page Title has an easy UI for that Meta Tags does not. When you can't use both modules, it's hard to choose if you don't know about adding a token for page enumeration, a major SEO flaw if you have duplicate page titles.

Summit’s picture

Hi,
May be stupid remark. But will it not work if you use different weights on the modules?
I am on travel, so I can't test it myself.
Greetings, Martijn

DamienMcKenna’s picture

Summit: Sure, but the point remains that there's no need for the Page Title module when using Metatag.

hass’s picture

But page title module allow users to customize the title per node. This is a feature I'm not aware of that metatags provides.

For sure I have installed latest released versions of both modules and there is no warning or error that stops me from doing it. For me it was just guessing that this may be the conflict. I have expected a bug in metatags. M is lower in order than P, so page title module wins the race :-(.

DamienMcKenna’s picture

@hass: Yes, you can override the page title per node or any other supported entity.

couturier’s picture

I think the difference between Meta Tags and Page Title that might confuse some people at the first look is that Page Title has a more extensive UI that simplifies the process of customization. Meta Tags actually does a lot more than Page Title can as far as functionality. It has amazed me, even in recent tech blogs around the web, how many people are suggesting the use of Page Title and Meta Tags together!

In comment #24 above I linked to a closed duplicate issue (sorry!). Here is the correct link that describes a key issue people are still confused about that is making them choose Page Title over Meta Tags, even though they don't need to:

Cache clearing for [current-page:page-number] to avoid duplicate page titles in Views and taxonomy term pages

vintorg’s picture

I have the same issue as #22, but I don't have the Page Title module installed.

couturier’s picture

@vintorg, and you have flushed your caches, both in Drupal and your browser caches?

vintorg’s picture

Yes.

couturier’s picture

@vintorg, some people have a front page that isn't a node (this issue).

Are you using the very latest dev version?

Have you disabled any other modules that provide meta data or page title support (I see you do not have Page Title, but check for any others, also)?

If you have double-checked your Meta Tags settings and they are correct, and if you have flushed all caches while testing, then I recommend filing a new issue with more information. This particular thread is a different issue.

vintorg’s picture

@couturier -- Yes, I have no conflicting modules, and this problem is only happening on the front page. The other pages are fine, and titles show up fine and all is hunky dory. The module is not working correctly ONLY on the front page.

I do have an open issue that isn't getting much love: http://drupal.org/node/1800658

DamienMcKenna’s picture

DamienMcKenna’s picture

detagged.

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

Last night saw the release of 7.x-1.0-beta1, so I'm closing all these "fixed" issues in the interest of tidying up the issue queue. Thank you all for your help getting us to this point!

neurojavi’s picture

Status: Closed (fixed) » Active

Hi:
I'm sorry to reopen this issue but I'm getting the global tags for my nodes. If I set a global title (or other tags) for nodes in global settings I get this title and not the global one (I mean that overrides in global settings are working). But if I change the title (or other tag) in the node edit form I don't get the new title on the page.

I thought it was a problem with DS but I've completely disabled DS and I'm getting the same results.

I'm using metag 1.0-beta4 and Zen 3.1.

Thanks.-

1mundus’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta4
Priority: Normal » Major

Unfortunately, I can also confirm this bug. However, I'm trying to edit term pages, nodes seem to work fine.

When I edit the term meta description, it reverts back to the default set for taxonomy terms. I don't check HTML output at all, since the edit form always displays the default. There isn't anything special used, I even use Seven theme for administration, so there isn't any custom templating included.

Raising to major, since overriding per page is an important function.

couturier’s picture

neurojavi and 1mundus, if you want to make page titles work, just use the Page Title module for now. Leave the titles in Meta Tag blank. Both modules will work together. We are hoping for more improvements in page title functions in Meta Tag, but it may not come until Drupal 8, depending on the time the developers have to give to it. Page Title seems to work better for me right now than Meta Tags for the titles settings.

If your meta tag settings are not changing, then are you sure you have flushed all caches after changing, both in Drupal and in your browser caches? You may need to just go with whatever global settings you have for the whole site for now. Remember that SEO is dependent on many things, and meta tags is one of the least. Page titles rank higher than meta tags for SEO purposes. Maybe you'll get a reply from DamienMcKenna with more advice.

1mundus’s picture

Unfortunately, I don't use Page Title module, so it can't be a problem. Page Titles are OK, it's impossible to change the description tag. I have cleared all of the caches, but nothing changes - there is always the default displayed in the edit form.

neurojavi’s picture

@coutier: Thanks for your suggestions but I need metatag for more than changing the title and is not possible for me to change metatags per node, so Page title is not enough for me. I think that this is a major problem and I don't think that the solution is using another module or wait for a D8 version. Metatags are useful for much more than SEO...

@1mundus: I think the you have a different problem that mine. My settings get saved (on nodes) but they are not displayed in HTML. The thing is that when I was making some tests I discovered that the metatag settings for the node I have edited were reset to default value (as yours) but this only happened one time and I was unable to reproduce. I thought it was due to an update from beta3 to beta4 I did...

1mundus’s picture

Could you try to test it with term pages? I would appreciate it.

neurojavi’s picture

I've checked it...

You are right: there's a problem there. I edit a term -> change metatag (title and description f.e.) -> save -> metags are changed (I can see the new ones) -> I edit the term again -> the metatags form is filled with default values (the new ones I typed in my first edit are lost) -> you save and you loose your metatag changes (you write default metatags).

That's what I'm seeing with terms... Maybe this is a different issue?

I think we'll have to wait some guidance from DamienMcKenna, but in the meantime can you test metatags overides in nodes?

Thanks.-

couturier’s picture

Have you upgraded to the newest Meta Tag released November 19?

DamienMcKenna’s picture

Status: Active » Closed (fixed)

I think this might be a continuation of a problem with the language handling - I thought I had it correct but evidently it needs some further poking.

Tell you what, lets move over to #1845326: Metatags not loading correctly with beta4 and let this issue rest.

DenisVS’s picture

Assigned: Unassigned » DenisVS
Status: Closed (fixed) » Active

Same actual bug now.
7.x-1.0-beta4
metatag-n1784896-13.patch failed.

DamienMcKenna’s picture

Status: Active » Closed (fixed)
DamienMcKenna’s picture

Issue summary: View changes

Create empty array in case no default condition is met (i.e Admin pages)