Opened 7 years ago
Last modified 4 years ago
#41403 new defect (bug)
Support "class" and "id" attributes on wp_oembed_get()
Reported by: | ramiy | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Embeds | Keywords: | needs-patch close dev-feedback |
Focuses: | Cc: |
Description
The oembed function wp_oembed_get( $url, $args )
allows us to set additional arguments for retrieving embed HTML.
The problem is that currently the function supports two arguments, only width
and height
. In some cases developers need more flexibility, to set other HTML attributes like id
, class
and maybe even title
(for better accessibility).
I was trying to thinking of an example and I think that the simplest example would be bootstrap responsive embeds.
<div class="embed-responsive embed-responsive-21by9"> <iframe class="embed-responsive-item" src="https://..."></iframe> </div>
Currently you can't set custom classes in iframe with the attributes:
wp_oembed_get( 'https://...', array( 'class' => 'embed-responsive-item' ) );
Change History (4)
This ticket was mentioned in Slack in #core by noisysocks. View the logs.
4 years ago
#2
@
4 years ago
- Component changed from General to Embeds
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#4
@
4 years ago
- Keywords dev-feedback added
@peterwilsoncc Thank you for clarifying that. But I think we can overcome this by adding a new parameter for for the container div wrapping the oEmbed provider html.
The wp_oembed_get( $url, $args, $container )
function will check if $container
is not empty, then a container will wrap the oEmbed html with custom Classes, IDs, Titles, aria-* tags, data-* tags and other attributes the developer want to put around the oEmbed code.
Another solutions is to filter thewp_oembed_get()
returned value. This way developers can add container divs.
This was discussed in a triage session today and moved to the Embed component as a result.
I suspect the reason only width and height are supported are due to the oembed spec, specifically the section on consumer requests:
With the exception of a few embed types, WP passes the data on to the provider to return the expected HTML. Accepting IDs and classes within WordPress would be possible but not often respected by providers.
I'll leave this open for now rather than closing it outright so someone else with further knowledge of embeds can provide some thoughts.