Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When using a Token for a field that can have multiple images the Token (correctly) outputs all image urls something like fileurl1.jpg, file2url.jpg. However Meta tag module also puts all these urls in the og:image, and Facebooks debug tool does not like multiple file urls in one og:image.
Not sure if Meta tag should fix this by using only the first url (which would make this a feature request for Meta tag),
or that we can/should solve this with a Token (maybe generated by imagefield_tokens or token_custom module).
Comment | File | Size | Author |
---|---|---|---|
#30 | metatag-1305402.patch | 1.65 KB | jofitz |
#9 | metatag_opengraph_imgfix.zip | 872 bytes | SilviuChingaru |
#3 | multiple_image-1305402-1.patch | 1.68 KB | SilviuChingaru |
#2 | multiple_image-1305402-1.patch | 2.18 KB | SilviuChingaru |
Comments
Comment #1
SilviuChingaru CreditAttribution: SilviuChingaru commentedFrom OpenGraph Array Documentation:
This is a bug in the module metatag_opengraph not properly handling multiple images.
I set the priority to major because the module does not meet opengraph standard and is practically unusable with multiple images.
Comment #2
SilviuChingaru CreditAttribution: SilviuChingaru commentedMy solution at first look...
Comment #3
SilviuChingaru CreditAttribution: SilviuChingaru commentedFixed patch mistake (patched .info file also) in patch from #2.
This is the correct patch.
Comment #4
SilviuChingaru CreditAttribution: SilviuChingaru commentedComment #5
tempo22 CreditAttribution: tempo22 commentedthis patch is working well
Thanks a lot
Comment #6
djschoone CreditAttribution: djschoone commentedGreat patch. Saved my day!
Comment #7
DamienMcKennaAt the very least this needs some tidying for Drupal's coding standards, but it's an interesting issue. I'll review this shortly.
Comment #8
mezitlab CreditAttribution: mezitlab commentedthis patch is working well with 7.x-1.0-alpha8 and 7.x-1.0-alpha8+10-dev (2012-Aug-26) too.
Comment #9
SilviuChingaru CreditAttribution: SilviuChingaru commentedUntil the core is fixed I made a helper module to fix this so you don't need to patch module after each update...
Comment #10
DamienMcKennaWhat happens if you upload an image with a comma in the filename?
Comment #11
SilviuChingaru CreditAttribution: SilviuChingaru commentedHmm... I don't upload files with comma in their name but this might be a problem... This was a temp patch to prove the concept not the final patch. Maybe I'll look deep into this when I'll have a little time... but I'm very busy right now...
Comment #12
aleksey.tk CreditAttribution: aleksey.tk commentedI think all the patches here are a wrong approach - there should be a proper token, like s1l said in initial issue description.
Comment #13
DamienMcKennaComment #14
DamienMcKennaComment #15
FiNeX CreditAttribution: FiNeX commentedOn beta5 using [node:field-image:file] returns a WSOD. This is the error on the log:
I've found this reference: http://drupal.org/node/1440928#comment-7066230.
Comment #16
DamienMcKenna@FiNexX: Thanks for referencing that bug, clearly there's a problem in Entity API.
Comment #17
GiorgosKother related issues #1487990: Token not working for Entity reference field (multiple values) and #1284810: Document how to handle images properly and some provide temporary solutions
Comment #18
manoloka CreditAttribution: manoloka commentedI think he is right and I thought that these tokens [node:field-fotos:?] were actually for that but they don't work
Comment #19
DamienMcKennaIf you've got Entity API installed too you should see two sets of tokens for each field - one using underlines and one dashes; try using the *other* token and see if that works.
Comment #20
manoloka CreditAttribution: manoloka commentedAfter trying the helper module at #9 and some research, I see that this is the right approach and the way the og:image tag must render images, 1 tag per image
Comment #21
Balbo CreditAttribution: Balbo commentedShould the code in #9 be ported in the module itself? Any news on this issue?
Comment #22
tfranz CreditAttribution: tfranz commented#9 worked for me – thank you!
And even better: this module solves another problem, for me, too:
If there's an image-field, use the image-field as opengraph-image.
Empty image-field? Use the site-logo!
Just enter all possibilities separated by commas, for example:
[node:field_image],[node:field_teaserimage],http://drupal.org/logo.jpg
To avoid empty image-values, change line 25:
Comment #23
doitDave CreditAttribution: doitDave commentedSorry, this here is in no detail about "guilt" or "fault" or "blame", this should be about improvement.
First of all, thanks to fiftyz for the simple and effective approach, this is pragmatism as I like it. Once you change
into
you can upload as many images with comma filenames as you wish.
Then, for an as like pragmatic follow-up:
1) If og:image wants a single URL, it is clearly in the metatag module's scope to deal with "inappropriate" tokens. As long as there is no [node:field_yo_mama_image:n] (see below), the fixed theming approach above is clearly the best idea IMO.
2) If there really is not yet a way to get the n-th value out of a field with multiple values, this is of course an important gap in the entity API (or the token-related modules for it). I would intuitively expect [node:field_whatever_image:n] to deliver the n-th single value out of a field. It really made me stumble that this seems to not yet have occured to anyone else.
@21 (Balbo): Yes, it should. Asap. Any customer requests og:image to work and any customer with, say, an online shop where most nodes will have multiple image fields will never understand why it is not possible by default to just do so. And he'd be right.
I would suggest integrating the fix in metatags and after that moving this issue to the most related entity or token project, wherever the mentioned gap may be filled as quickly.
tia!
Comment #24
rvallejo CreditAttribution: rvallejo commented@fiftyz: Thanks for the code! I'm including it for now in a custom module I've made for commerce-related metatags (as well as a similar fix for the twitter:image tag).
I'll add some attribution to the code when I commit it later today. It's a necessary fix if you wanna do anything with Pinterest rich pins or Twitter Cards, which is exactly what I'm trying to do with a Drupal Commerce-based site and is why I've included the code in the module for now. I assume the code should make it into the appropriate Metatag submodules eventually though.
If you want to take a look at the sandbox module, it's at https://drupal.org/sandbox/rvallejo/2102725.
Comment #25
DamienMcKenna@rvallejo: Excellent! I've submitted a few issues for your sandbox, we can discuss them over there.
Also, I've added a new issue to help drive Commerce integration further: #2103321: Identify new/missing/incomplete ecommerce-related meta tags
Now, back to the topic on hand - how to handle multiple images.
Comment #26
eigentor CreditAttribution: eigentor commentedSo here is another temporary solution for those stumbling upon this issue.
Put this in the template.php file of your theme, replace YOURTHEME with the name of your theme.
It uses the comma and space after each image as a delimiter and strips all images from the og:images metatag but the first.
Not the solution this issue is heading for, but sure helpful for people who want to use the metatag module and need a solution on their site now.
Comment #27
idealdesigns CreditAttribution: idealdesigns commentedModification for #26 solution:
to check if 'metatag_og:image' exists to avoid php errors and to alter only multiple field images, for field with single image the If statement will skip it
Comment #28
Clint Eagar CreditAttribution: Clint Eagar commentedHi @idealdesigns how would I make this work for
<link rel="image_src" ???
Metatags module has the same problem with this advanced field.
Comment #29
surfgatinho CreditAttribution: surfgatinho commentedThanks - #26 , #27 worked for me
Surprised more people haven't encountered this issue...
Comment #30
jofitz CreditAttribution: jofitz commentedHere is the patch from #3 re-rolled for beta7.
Comment #31
Frederic wbase CreditAttribution: Frederic wbase commentedPatch from #30 works like a charm.
Time to change status to RTBC?
Comment #32
cs_shadow CreditAttribution: cs_shadow commentedComment #33
cs_shadow CreditAttribution: cs_shadow commentedPatch #30 works for me. Can RTBC.
Comment #34
cimo75 CreditAttribution: cimo75 commentedHi
i ve installed the patch but I still get all the images URLs comma separated
Comment #35
leewoodman CreditAttribution: leewoodman commentedIs this patch available for the current release version?
Comment #36
cimo75 CreditAttribution: cimo75 commentedThe patch did its thing on beta9 but I can t see any useful output.
Comment #37
GuillaumeDuveauThanks for #27
Comment #38
leewoodman CreditAttribution: leewoodman commented#27 worked for me. I also had the same issue with link rel="image_src" so i did the same as #27
Comment #39
Lukas von BlarerThe re-roll affects og:description as well.
Comment #40
GuillaumeDuveauSame problem with Twitter Cards
Comment #41
DamienMcKennaClosed a duplicate: #2223263: Open Graph Image + Field multiple images
Comment #42
DamienMcKennaThank you for the patches, but we're going to make this a general API change in #1282636: Support meta tags that allow multiple values (repeated tags).
Comment #43
DamienMcKennaFYI I've committed some code in #1282636: Support meta tags that allow multiple values (repeated tags) that supports this feature - even though I didn't use the work from this issue I really do appreciate the effort everyone put into it!
Comment #44
haysuess CreditAttribution: haysuess commentedI have tons of products with multiple images. The committed code in #43 puts multiple og:image tags in my source code, but adds the images in alphabetical order.
I need one of the two:
Can anyone help?
Comment #45
DamienMcKenna@hayseuss: Lets move your bug into #2281833: Multi-item fields should output in the same order as input, thanks for reporting it.
Comment #46
kopeboy CreditAttribution: kopeboy commentedHas the working patch in #30 been included in any stabe release?
Facebook sharer still isnt working with images cause all my product nodes have multiple images..
This cause facebook to automatically load images from the page, which can be the wrong ones and with wrong resolutions
Comment #47
manoloka CreditAttribution: manoloka commentedHave you tried the approach at #9 ... as I see it, right now is the best way to go.
It worked for me.
Comment #48
DamienMcKennaPlease stop replying to this issue, please use the current -dev release (or the next beta / RC release) and open up a new issue to discuss any other problems you have with the functionality. Thank you.