Some meta tags support multiple values (like og:image). Need to investigate how this could possibly be done and if it's worth it. This feature would be very uncommon.

#14 metatag-n1282636-14.patch5.7 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es). View
#12 metatag-n1282636-12.patch17.71 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es). View
Members fund testing for the Drupal project. Drupal Association Learn more


DamienMcKenna’s picture

Version: » 7.x-1.x-dev

FYI many Dublin Core meta tags also support multiple values, so it should IMHO be an API option to allow multiple values. In Nodewords I've handled it by changing the normal textfield to a textarea and splitting on linebreaks.

the_loeki’s picture

I think it'd be a very useful feature, and not *that* uncommon. For example, when sharing to FaceBook, FB will index all og:images as image selection during sharing.

DamienMcKenna’s picture

The simple solution would be to show a textarea field for these meta tags and then parse it for linebreaks? I need to look into how the token parsing handles multiple values too..

moehac’s picture

All of our site's articles have multiple rich images per article. This would be superb if accomplished.

DamienMcKenna’s picture

alayham’s picture

When sharing to facebook from a community site, it is favourable to allow multiple images for the link, like an image or multiple images from the content, the profile pic of the author, and the logo of the site.

circuscowboy’s picture

Issue summary: View changes

I need this functionality for dublin core audiences. It can be a multiselect. In my naivety I just used checkboxes in my hook metatag info but obviously it didn't work. I have a bit of time that I can devote to a patch to make this work. Looking under the hood things are quite complex and if I had some direction it would make my time more efficient.

Direction ideas:

In terms of checkboxes or multiselect we already have an array and just need to get each item processed.
For text fields there needs to me something that separates the items (space, comma, semicolon, linebreaks) and then we can explode it into an array and continue as previous.


circuscowboy’s picture

Well I obviously wrote before I thought.

I now see there is a class for Lists that works fine as a comma delimited list.
This actually works fine for me.

Dublin core standard does state that each item should have its own line

Where a collection is intended or useful for multiple audiences, a separate statement should be used for each audience.


It looks like it would be be good to have them separated for multiple reasons but it also looks like it would be going against the grain of how things were created.

I still can spend some time on this patch if someone can give me some direction but no longer need the results.


DamienMcKenna’s picture

DamienMcKenna’s picture

DamienMcKenna’s picture

Title: Figure out how to support multiple same meta tags » Support meta tags that allow multiple values (repeated tags)

So there are a few pieces to this.

Firstly, it's perfectly reasonable to want to have multiple tokens output in one field and have the module pick the first value that is appropriate for use; this use case is covered by [#2271301.]

This issue is focused on having multiple values in one meta tag all output correctly as multiple HTML tags, the primary example being og:image.

Right now, when a token is added for a single field that allows multiple values, each value is output in a comma+space separated list. If multiple tokens are added the module does not automatically add a comma separator, instead they are output exactly the way they're defined, e.g. "[node:field_1][node:field_2]" becomes "OrangeBanana" instead of "Orange Banana" or "Orange, Banana".

DamienMcKenna’s picture

Status: Active » Needs review
17.71 KB
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es). View

This makes a few changes:

  • A new 'multiple' value is added to the items in hook_metatag_info(), if the value is TRUE then the output is split on a comma separator.
  • Tags that allow multiple values will have an additional note added to the description indicating the new functionality.
  • The Transliteration module is now recommended, so that it can clean up uploaded filenames and hopefully avoid scenarios where filenames are uploaded that contain a comma, thus potentially leading to broken image meta tags.
  • So far only the og:image meta tag has had the 'multiple' option enabled, I need to work out which others should support this option.
  • The API docs have not been updated yet.
  • I removed theme_metatag_opengraph and instead added theme_metatag_property, and updated all OG meta tags to use the new function.
  • I simplified the OG meta tag definitions by using a set of common default values that was appended, rather than needlessly duplicating five lines for each one.

The last two items I might move into a separate issue, just to keep this one more focused.

DamienMcKenna’s picture

I've moved the Metatag:OpenGraph code cleanup into #2271811: Replace theme_metatag_opengraph with theme_metatag_property.

DamienMcKenna’s picture

5.7 KB
PASSED: [[SimpleTest]]: [MySQL] 73 pass(es). View

Rerolled after #2271811: Replace theme_metatag_opengraph with theme_metatag_property was committed, along with a few small fixes.

DamienMcKenna’s picture

Status: Needs review » Fixed

Seems to work fine in my testing.

  • Commit 9f61eac on 7.x-1.x by DamienMcKenna:
    Issue #1282636 by DamienMckenna: Support meta tags that allow multiple...

Status: Fixed » Closed (fixed)

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

haysuess’s picture

This code works, but it adds the images in alphabetical order, rather than how they are ordered in Drupal.

Is there a way to add them in the same order that they appear in Drupal?

Or, as others have asked in other threads, I'd like to use [node:field_image:0] to just display the first image, but there's no way to get it to work based on all the searching I've done.

DamienMcKenna’s picture

@hayseuss: Lets move your bug into #2281833: Multi-item fields should output in the same order as input, thanks for reporting it.