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,
Comments
Comment #1
marcelovaniI agree, http://drupal.org/node/1732538#comment-6524698
Comment #2
jmart CreditAttribution: jmart commentedI think the problem is with the not operator:
When I take out the ! and change !path_is_admin(current_path()) to path_is_admin(current_path()), it works:
So the final is
That's because
Comment #3
marcelovaniDefault metatags are being loaded instead of metatags saved on the entity.
I have created a patch for the dev version.
Comment #4
marcelovaniThat still overrides the array, this new patch will fix it by merging the arrays i.e. global and content
Comment #5
marcelovaniComment #6
marcelovaniRe-done the patch to fix an error when trying to merge an empty array
Comment #8
marcelovani#6: overriding-metatags-fall-back-parent-default-value-1784896.patch queued for re-testing.
Comment #10
marcelovaniTest if failing for some reason, I am submitting again
Comment #11
marcelovaniComment #12
couturier CreditAttribution: couturier commentedThis patch works when used in combination with this patch from the issue, Support taxonomy term pages until taxonomy supports hook_entity_view().
Comment #13
DamienMcKennaI 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()?
Comment #14
DamienMcKennaComment #16
DamienMcKennaLets try this again.
Comment #17
DamienMcKenna#13: metatag-n1784896-13.patch queued for re-testing.
Comment #18
couturier CreditAttribution: couturier commentedThis patch works for me when used together with this patch in Support taxonomy term pages until taxonomy supports hook_entity_view().
Comment #19
kbasarab CreditAttribution: kbasarab commentedCan 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.
Comment #20
DamienMcKennaMarked #1426424: Allow overriding Open Graph (OG) tags per node as a duplicate.
Comment #21
DamienMcKennaCommitted! Thanks for the work identifying this problem, marcelovani.
Comment #22
hass CreditAttribution: hass commentedI 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 asMy site name |
what is also not[current-page:title] | [site:name]
.Is this the patch for this issue?
Comment #23
hass CreditAttribution: hass commentedDisabled page title module and now metatags works as expected.
Comment #24
couturier CreditAttribution: couturier commented[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.
Comment #25
Summit CreditAttribution: Summit commentedHi,
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
Comment #26
DamienMcKennaSummit: Sure, but the point remains that there's no need for the Page Title module when using Metatag.
Comment #27
hass CreditAttribution: hass commentedBut 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 :-(.
Comment #28
DamienMcKenna@hass: Yes, you can override the page title per node or any other supported entity.
Comment #29
couturier CreditAttribution: couturier commentedI 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
Comment #30
vintorg CreditAttribution: vintorg commentedI have the same issue as #22, but I don't have the Page Title module installed.
Comment #31
couturier CreditAttribution: couturier commented@vintorg, and you have flushed your caches, both in Drupal and your browser caches?
Comment #32
vintorg CreditAttribution: vintorg commentedYes.
Comment #33
couturier CreditAttribution: couturier commented@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.
Comment #34
vintorg CreditAttribution: vintorg commented@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
Comment #35
DamienMcKennaContinuing the discussion in #1800658: Front page settings don't work on some themes (e.g. TopHit).
Comment #36
DamienMcKennadetagged.
Comment #37
DamienMcKennaLast 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!
Comment #38
neurojavi CreditAttribution: neurojavi commentedHi:
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.-
Comment #39
1mundus CreditAttribution: 1mundus commentedUnfortunately, 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.
Comment #40
couturier CreditAttribution: couturier commentedneurojavi 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.
Comment #41
1mundus CreditAttribution: 1mundus commentedUnfortunately, 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.
Comment #42
neurojavi CreditAttribution: neurojavi commented@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...
Comment #43
1mundus CreditAttribution: 1mundus commentedCould you try to test it with term pages? I would appreciate it.
Comment #44
neurojavi CreditAttribution: neurojavi commentedI'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.-
Comment #45
couturier CreditAttribution: couturier commentedHave you upgraded to the newest Meta Tag released November 19?
Comment #46
DamienMcKennaI 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.
Comment #47
DenisVSSame actual bug now.
7.x-1.0-beta4
metatag-n1784896-13.patch failed.
Comment #48
DamienMcKennaLets continue in #1845326: Metatags not loading correctly with beta4.
Comment #48.0
DamienMcKennaCreate empty array in case no default condition is met (i.e Admin pages)