Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Metatag uses hook_entity_view() to load its data on individual pages (#1363476: Panels integration - ensure meta tags work OOTB on entity pages). Due to a core bug (#1067120: Missing hook_taxonomy_term_view() or hook_entity_view() when viewing a term) the taxonomy term pages in both Drupal 7 & 8 do not trigger this hook, so we need a temporary solution until that issue is resolved & backported to D7.
Comment | File | Size | Author |
---|---|---|---|
#38 | metatag.zip | 8.43 KB | waveer |
#31 | metatag-n1700160-29.patch | 780 bytes | DamienMcKenna |
#23 | support-taxonomy-term-pages-1700160.patch | 613 bytes | marcelovani |
#18 | support-taxonomy-term-pages-1700160.patch | 773 bytes | marcelovani |
#9 | support-taxonomy-term-pages-1700160.patch | 872 bytes | marcelovani |
Comments
Comment #1
DamienMcKennaBump.
Comment #2
himagarwal CreditAttribution: himagarwal commentedHas anyone found any solution to this problem?
Subscribing.
Comment #3
DamienMcKennaI think waiting for #1067120: Missing hook_taxonomy_term_view() or hook_entity_view() when viewing a term is the best plan - it's RTBC, we just need one of the core committers to commit it.
Comment #4
couturier CreditAttribution: couturier commentedI'm new here, so I don't know if there might be something that can be done for the issue referenced in #3 to get the attention of a core committer. It looks like more progress has been made in the last few days on a patch, and they are saying that if it doesn't get committed soon, it will have to be re-rolled. Is there some way to speak up on IRC about it or submit a special request elsewhere to get it committed?
Comment #5
DamienMcKenna@couturier: THe D8 maintainers are exceedingly busy and are prioritizing their time as they're best able; promises of baked goods and/or chocolate have not been able to influence them, so I suggest just being patient. Until then the patch in comment #73 should still work with the current D7 release, but let me know if it needs to be rerolled.
Comment #6
couturier CreditAttribution: couturier commentedYes, I saw your offer of food earlier up in the comments on that issue. Smart thinking. Too bad doughnuts can't be emailed or it might actually work. I hadn't thought to apply the patch to D7 myself, so thanks for that (I'm very new to website development). Too bad the patch can't be committed now and save you having to re-do your work. Can they take on a few more core maintainers to help out with the time crunch? Sounds like you know what you are doing and would be a good addition to the team, though I realize the time commitment to being a core maintainer is not possible for everyone.
Comment #7
remkovdz CreditAttribution: remkovdz commentedI can't follow all this technical talk 100%, so I hope someone can clarify for me?
All the Taxonomy changes I make in the Meta Tag module do not have any effect at all: nothing shows up in the code frontend. This is a known issue and I should not investigate further? Thanks a lot.
Comment #8
DamienMcKenna@remkovdz: Correct. Hopefully we'll get the fix rolled out soon for Drupal core so these pages work again.
Comment #9
marcelovaniWe need this functionality, so I am adding a patch that will do the job until the hook is implemented
Comment #10
marcelovaniComment #11
couturier CreditAttribution: couturier commentedThe patch applies without breaking anything, but when I tried to make a change to the way
<title>
is displayed for taxonomy term pages, my changes are not implemented.Comment #12
DamienMcKenna@couturier: What are you using for the display - core functionality, Panels, Views, etc?
Comment #13
couturier CreditAttribution: couturier commentedFor the taxonomy term page, it was core functionality Drupal 7. I do not have Panels installed. If you want me to create a View to test that, I can. Update: actually, I am concurrently working on a related issue where I have installed a patch from marcelovani that adds page numbers to
<title>
on Views pages and taxonomy term pages when [current-page:page-number] is added to the Global title settings, so we would not need this patch for Views pagination, because the other one works. That is a major concern for SEO and why I'm following this issue here as related to it.Comment #14
DamienMcKenna@couturier: That's ok, I'll be testing the patch this evening.
Comment #15
DamienMcKenna@marcelovani: The patch won't work as metatag_entity_has_metatags() is only called from metatag_entity_view() which won't be called on taxonomy term pages due to the lack of hook_entity_view() on those pages.
Comment #16
marcelovani@DamienMcKenna you are right. It is working for us because we use views to list all nodes that refer to a specific term i.e. /taxonomy/term/6, which triggers the hook_entity_view when loading nodes.
I will try find a better way of fixing this.
Comment #17
Molfar CreditAttribution: Molfar commentedThis patch didnt work for me.
Comment #18
marcelovaniThis logic is much cleaner than the previous one.
Comment #19
marcelovaniComment #20
couturier CreditAttribution: couturier commentedI'm not sure if I did something wrong, but I'm getting these warning messages on a taxonomy term page when I applied the patch. The custom title I set up in Meta Tags for taxonomy terms is not showing, either. It is showing only the Global settings.
Comment #21
DamienMcKenna@marcelovani: The correct arguments for hook_entity_view() are:
Therefore your code needs to be updated to pass in values for the above.
Comment #22
marcelovaniI have added default values for the function:
-function metatag_entity_view($entity, $entity_type, $view_mode, $langcode) {
+function metatag_entity_view($entity, $entity_type, $view_mode = 'full', $langcode = NULL) {
So that if we don't supply the other two arguments, it will use the default values
@DamienMcKenna, I would like to have a chat on skype, are you available: my skype is marcelovani
Comment #23
marcelovaniTo make things simpler, I am adding the two parameters when I call hook_entity_view.
Comment #24
marcelovaniComment #25
marcelovaniI am testing the patch on few sites.
Applying this patch alone won't fix the problem of overriding metatags for nodes/terms.
Image this case scenario:
- I set title metatag for terms to be [term:name] | [site:name] (/admin/config/search/metatags)
- I visit a term page /term/1 and the title shows term1 | test.com
- I edit the term and change the title metatag to Custom title for term1 (/taxonomy/term/1/edit)
- I visit a term page /term/1 and the title shows Custom title for term1
The scenario above will only happen if you also apply this patch http://drupal.org/node/1784896#comment-6534684
Otherwise, it will still show term1 | test.com, because the value gets overriden with the current code.
Please apply both patches (http://drupal.org/files/support-taxonomy-term-pages-1700160_1.patch, http://drupal.org/files/overriding-metatags-fall-back-parent-default-val...) and let me know how it goes, I am testing this on 6 different sites which have different modules and configuration, so far it seems to work fine.
Comment #26
couturier CreditAttribution: couturier commentedYes! With these two patches, the titles for taxonomy term pages can be successfully changed, independently from the Global settings.
Comment #27
Molfar CreditAttribution: Molfar commented#23: support-taxonomy-term-pages-1700160.patch queued for re-testing.
Comment #28
DamienMcKennaThis appears to work quite well. I'm going to test it further, and I'd like some feedback from Dave, but I like what I see.
Comment #29
DamienMcKennaPlease test out this alternative to #23 that skips the custom logic if #1700160: Support taxonomy term pages until taxonomy supports hook_entity_view() has been applied (please! please! please!).
Comment #30
couturier CreditAttribution: couturier commented@DamienMcKenna I'm not sure what you are asking. Do you want Dave to review the #23 patch? I do not see any alternative to the patch in #23. Or, maybe you mean the patch in #23 plus your new patch here? I can try that.
Comment #31
DamienMcKennaDoh, forgot to attach the file.
Comment #32
couturier CreditAttribution: couturier commentedYes, this patch in #31 works for me to set unique taxonomy term page titles (separate from Global settings) when used together with your new patch under "Overriding meta tags fall back to parent default tag value".
Comment #33
remkovdz CreditAttribution: remkovdz commentedFor me only #9 is working, and all the others are not. Thanks still!
Comment #34
DamienMcKennaI've committed the patch from #31, thank you again marcelovani for your help. If there are any issues with meta tags still not working please review one of the issues related to the display system being used (Display Suite, Views, Panels, etc) or open a new issue.
Comment #35
DamienMcKennaFYI, a change notice for one of the two hooks added: http://drupal.org/node/1808870
Comment #36
waveer CreditAttribution: waveer commentedComment #38
waveer CreditAttribution: waveer commentedi test the code according to the #32
the patch is a little troublesome to use
so i upload my modified metatag.module file
it has two modify
1. add add line 445-455
2. modify function metatag_page_build() line 861
我测试了32楼的代码,可以正常使用
patch看着有点麻烦
不想麻烦的,可以直接看我上传的metatag.module
改了两个地方
1 是 添加 行445-455
2 修改默认的 function metatag_page_build() 行861
Comment #39
DamienMcKenna@waveer: Or you could just download the latest -dev codebase ;-)
Comment #40
waveer CreditAttribution: waveer commentedthank you.
dev is better in drupal :-)
Comment #41
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 #42
DamienMcKennaRelated: #1836976: Get rid of metatag_taxonomy_term_view_alter
Comment #43
charlie-s CreditAttribution: charlie-s commentedI'm using D7.17 and the latest dev release of Metatag but am seeing no meta tags printed on my taxonomy term pages. The tags are in $vars['page']->content['metatags'] but they're simply not being printed. All of my nodes are getting them printed properly. Should I be expecting this to work with 7.17 and 7.x-1.x-dev?
Comment #44
DamienMcKenna@csdco: Sounds like a theming problem, please check e.g. #1310780: Metatags not working on overwritten templates.
Comment #45
charlie-s CreditAttribution: charlie-s commentedThat issue is interesting – following the advice there, I've thrown
into template_preprocess_html() and the metatags are now printing. Still not getting the revised title, however. This makes me think that my issue is related to both this issue and 1310780. Metatags are not being rendered for taxonomy terms, including the title tag.
Comment #46
couturier CreditAttribution: couturier commentedDoes this patch need to be removed from Meta Tag now with the release of Drupal 7.17 on November 7, 2012?
Comment #47
DamienMcKenna@couturier: The code in beta2 will identify whether the custom logic is necessary, so you're good to go.
Comment #48
remkovdz CreditAttribution: remkovdz commentedBeta2 works great for me, thanks a lot.
Comment #49
couturier CreditAttribution: couturier commentedSmart, Damien. Thanks for the forethought in beta2.
Comment #49.0
couturier CreditAttribution: couturier commentedAdded link to #1363476.
Comment #50
DamienMcKenna