Some meta elements, like the canonical tag, are not added as <meta> tags but as <link> tags (see also http://googlewebmastercentral.blogspot.com/2009/02/specify-your-canonica...). This patch checks known tags as specified in known_tags.inc, and outputs a link tag if the known tag type equals 'head_link'.

While this is an improvement over the current situation, it is not perfect yet. Since node.module also adds a default canonical tag, metatags_quick should make sure that the default canonical tag is removed when a page-specific one is defined.

Looking forward to your reactions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

valthebald’s picture

Frankly, canonical added by the node module was the main reason for me not including it here.
I will definitely have a look at your patch, because the problem exists.
Thank you!

marcvangend’s picture

FileSize
2.07 KB

Thanks for your quick reaction. Here is an improved patch, which also solves the problem of duplicate link tags.

I have tried to make it as generic as possible, but it's not as clean as I'd like it to be. The code unsets existing link tags with the same rel attribute, so only one can exist. That makes sense for values like rel="canonical", rel="shortlink" and rel="shortcut icon", but I'm not 100% sure if this approach will prove to be future proof. For now at least it will do, because currently known_tags.inc only contains one element ('canonical') with type head_link anyway.

marcvangend’s picture

FileSize
2.11 KB

Minor improvement compared to the previous patch: checking if a value is set to prevent notices.

valthebald’s picture

Status: Needs review » Needs work

IMO, the best way to add link head element is to modify metatags_quick_field_formatter_view() by adding new formatter 'link'. That will require minimum changes

arcticShadow’s picture

Hey everyone,
This patch works for me, Although with the most recent version of metatags_quick the line numbers don't match up so i patched the file manually.

I have been using this successfully one one site for a few months, but i came to use it on a different site this morning, and it wasn't working with nodes.

The issues i had is that canonical fields (For existing entities) created with metatags_quick module wern't saving data. I instead had to create the field in the content type manager and give it meta type etc... and now it works. I don't know if this is an issue with the patch(I don't think so) or with meta tags module. I'm just making note for future people passing through (And likely myself in 6 months time)

dimitriseng’s picture

Hi. I have tested #3 and it seems to be working ok. Is this the final solution or a more appropriate solution should be considered? Thanks.

valthebald’s picture

I personally think that using different formatter for the link tag is better, but if patch works for you - why not...

valthebald’s picture

Category: bug » feature
dimitriseng’s picture

@valthebald The patch is working but if you believe that there is a better way of doing this then I think that this should be implemented. In the meantime I guess that we can keep using the patch, I will report any issues. Thank you for your good work on this.

valthebald’s picture

Status: Needs work » Active
FileSize
3.15 KB

I thought of formatter-based solution, like in attached patch. What do you think?

dimitriseng’s picture

@valthebald, thanks for the quick response!
Using D7.10 + metatags_quick 7.x-2.3.

As I said #3 works as expected, your approach looks more logical but it is up to you to decide :)

- I applied patch #10.
- Also, I had to uncomment the definition for 'canonical' in known_tags.inc as this was commented out (is this required?).
- In the metatags_quick general settings I attached 'CANONICAL URL' to my content type and confirmed the field was created correctly.
- In the "Manage Display" of the content type I changed the 'FORMAT' for '(Meta)Canonical URL' to "Link head element' and saved.
- Created a node.
- When not setting a value for '(Meta)Canonical URL', the default Drupal canonical URL link tag is generated in the head.
- When setting a value for '(Meta)Canonical URL', metatags_quick is adding correctly the link tag for canonical, but I can also see that the defaul Drupal one is still getting generated. This was not the case with #3.

Is the procedure correct?

So, I think that #10 is working correctly but the only issue I see at the moment is that the default Drupal canonical URL is also in head, as well as the metatags_quick when it is set. Can you please check this? Thank you.

dimitriseng’s picture

@valthebald, did you get a chance to have a look at this? This is the only thing preventing me from using this module for a live site. The only issue I see is that the Drupal canonical URL is also included in head, as well as the matatags_quick when it is set (please see #11 for more information). Also, are you planning to commit this functionality to the module once it is working ok?Many thanks for your help.

valthebald’s picture

So far I couldn't find a way to suppress default canonical tag of drupal.
Any idea how this could be done?

dimitriseng’s picture

Thanks for looking at this. Unfortunately I am not sure how this could be done.

Does anybody know how to suppress the default canonical tag of Drupal? Apart from that, the rest of the functionality seems to be working ok, so it would be great to get this working too.

Do you think that if it is not possible to get this to work properly that we should consider the approach in #3 which seems be working ok, although the approach in #10 seems to be more appropriate? Thanks.

valthebald’s picture

I will take an idea of hiding drupal canonical tag from patch #3
Writing this from mobile, but hope to submit new patch tomorrow

valthebald’s picture

Assigned: Unassigned » valthebald
Status: Active » Needs review
FileSize
4.67 KB

Here's the patch
Canonical tag coming from drupal core is hidden if it overlaps with manually set field

dimitriseng’s picture

Hi valthebald, thanks for checking this quickly! I have applied the updated patch at #16 and I can confirm that now the default drupal canonical URL is not added to head when the canonical URL is set manually using metatags_quick, so I think that this fixes this issue, thank you!

valthebald’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mexicoder’s picture

Did this fix make it into the latest release? Seem as though it is still adding a meta tag and not replacing the default drupal canonical link?

spidersilk’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

I second mexicoder's comment - this doesn't appear to be fixed at all, at least not in the current stable release. I tried setting the canonical URL for the home page of the site I'm working on to https://sitename.com, and now I have the following:

<meta name="canonical" content="https://sitename.com/" />
<link rel="canonical" href="/alias-of-page-used-as-home-page" />
<link rel="shortlink" href="/node/nid" />

(where sitename, alias-of-page-used-as-home-page and nid are the actual domain, alias and nid, not the generic versions I used here to protect the client's privacy)

So now it's got two canonical tags in two different formats, plus a shortlink tag, all pointing to different URLs. That can't be good...