Would it be possible to make the output markup more accessible by adding a title attribute with the video title to the iframe tag?

Members fund testing for the Drupal project. Drupal Association Learn more


nickgrace’s picture

Category: bug » feature
guschilds’s picture

The video title is not saved in the database and therefore must be fetched from youtube to be used (see #1916756: Provide function or ability to display YouTube video's title). You could use the code in #1's patch while overriding theme_youtube() if you'd like, but I don't think it will end up in the module.

Regardless, the iframe's title attribute should at least be given a generic value, such as t("Embedded YouTube video content"). Thoughts?

pagaille’s picture

Any title would be better than no title, but the actual title would be best of all.

guschilds’s picture

Attached is a patch that assigns the YouTube video's title as the title attribute of the embedded iframe. There is an option to disable this and instead provide a default value of "Embedded YouTube video player" (admin/config/media/youtube). The option exists to not require that the extra request via file_get_contents() is made.

To test, please:

  1. Apply the patch in #6 to YouTube Field 7.x-1.0 and clear cache.
  2. View the source of an embedded YouTube video output by a YouTube Field field.
  3. Verify that the correct YouTube video title is set as the title attribute of the iframe.
  4. Navigate to admin/config/media/youtube and uncheck "Assign the YouTube video's title as the title attribute of the embedded iframe".
  5. Click "Save configuration" and repeat step #2. This time the title attribute should read "Embedded YouTube video player" instead.
guschilds’s picture

See #6.

guschilds’s picture

Status: Active » Needs review
2.55 KB

Attached is a fixed patch that ensures the YouTube video's data was successfully retrieved before grabbing the title.

guschilds’s picture

Version: 7.x-1.0 » 8.x-1.x-dev
Issue summary: View changes
Status: Needs review » Needs work

Bumping this back up so it gets addressed. The video iframe should have a title. The title probably shouldn't come from the actual YouTube video, as the above patches implement, because it would rely on an external call to YouTube for every video load (unless caching was introduced). However, as #3 mentions, any title is better than no title. Perhaps it should be something like title="YouTube video for [node:title]" or more generic, title="Embedded YouTube video".

This is needed for 8.x-1.x and 7.x-1.x.


  • guschilds committed 46de1a8 on 8.x-1.x
    Issue #2085749 by guschilds: Added title tag to embedded video elements.

  • guschilds committed 2bb007d on 7.x-1.x
    Issue #2085749 by guschilds: Added title tag to embedded video elements.
guschilds’s picture

Status: Needs work » Fixed

A title tag has finally been added to the iframe element in both the 7.x-1.x and 8.x-1.x branches. The title goes by the format "Embedded video for [entity:title]". See the previous discussion for more information. Thanks to everyone involved.

Status: Fixed » Closed (fixed)

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