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,

Files: 
CommentFileSizeAuthor
#13 metatag-n1784896-13.patch1.5 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]
#10 overriding-metatags-fall-back-parent-default-value-1784896.patch960 bytesmarcelovani
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]
#6 overriding-metatags-fall-back-parent-default-value-1784896.patch1.01 KBmarcelovani
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch overriding-metatags-fall-back-parent-default-value-1784896_1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#4 overriding-metatags-fall-back-parent-default-value-1784896.patch914 bytesmarcelovani
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]
#3 overriding-metatags-fall-back-parent-default-value-1784896.patch899 bytesmarcelovani
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

Comments

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

StatusFileSize
new899 bytes
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

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

StatusFileSize
new914 bytes
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

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

Status:Active» Needs review

StatusFileSize
new1.01 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch overriding-metatags-fall-back-parent-default-value-1784896_1.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

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.

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.

StatusFileSize
new960 bytes
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

Test if failing for some reason, I am submitting again

Status:Needs work» Needs review

Status:Needs review» Reviewed & tested by the community

Status:Reviewed & tested by the community» Needs work
StatusFileSize
new1.5 KB
PASSED: [[SimpleTest]]: [MySQL] 15 pass(es).
[ View ]

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()?

Status:Needs work» Needs review

Status:Needs review» Needs work

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

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

Lets try this again.

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

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.

Status:Reviewed & tested by the community» Fixed

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

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?

Disabled page title module and now metatags works as expected.

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

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

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

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 :-(.

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

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

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

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

Yes.

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

@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

detagged.

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!

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

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.

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.

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.

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

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

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

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

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.

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

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

Status:Active» Closed (fixed)

Issue summary:View changes

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