Cross-posting my answer from https://stackoverflow.com/a/55053642/799327, hope that\'s okay since it\'s from the same OP:
So, after some research on this, the best way to do this is to leverage the oembed_fetch_url
filter hook to add extra arguments to the oEmbed request URL. My specific goal was to allow an autoplay paramater, but this method is built to be easy to tailor to any oEmbed argument you need.
First, add this to your functions.php
:
<?php
/**
* Add parameters to embed
* @src https://foxland.fi/adding-parameters-to-wordpress-oembed/
* @src https://github.com/WordPress/WordPress/blob/ec417a34a7ce0d10a998b7eb6d50d7ba6291d94d/wp-includes/class-oembed.php#L553
*/
$allowed_args = [\'autoplay\'];
function koa_oembed_args($provider, $url, $args) {
global $allowed_args;
$filtered_args = array_filter(
$args,
function ($key) use ($allowed_args) {
return in_array($key, $allowed_args);
},
ARRAY_FILTER_USE_KEY
);
foreach ($filtered_args as $key => $value) {
$provider = add_query_arg($key, $value, $provider);
}
return $provider;
}
add_filter(\'oembed_fetch_url\', \'koa_oembed_args\', 10, 3);
This function takes the generated oEmbed URL and its corresponding arguments and checks it agains a hard-coded list of whitelisted arguments, in this case [\'autoplay\']
. If it sees any of these whitelisted keywords in the arguments passed to the oEmbed filter, it adds them with their given value to the oEmbed URL.
Then, all you need to do is add the oEmbed parameter to your shortcode in the Wordpress editor, like this:
[embed autoplay="true"]https://vimeo.com/1234567890/1234567890[/embed]
Be aware that the oEmbed class in WP uses the postmeta as a cache for these requests, so if you\'ve embedded the target URL before, you might have to clear your postmeta cache in some way or add a cache buster of some kind to the target URL. If the link is in the cache, the filter hook will never get to run.
I hope this makes sense, as I feel like it\'s a pretty useful feature that\'s surprisingly hard to figure out how to achieve.