Created
August 9, 2022 12:52
-
-
Save webgurus/97dd46d6915046ee300be215e3400f37 to your computer and use it in GitHub Desktop.
Modify ACF oEmbed field to add attributes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add custom attributes to oEmbed iframe src | |
* | |
* @param string $iframe | |
* @return string | |
*/ | |
public static function oEmbedIframe($iframe) { | |
// Use preg_match to find iframe src. | |
preg_match('/src="(.+?)"/', $iframe, $matches); | |
$src = $matches[1]; | |
// Add extra parameters to src and replace HTML. | |
$params = array( | |
'showDescriptions' => 0, | |
'autoPlay' => 1, | |
'autoMute' => 1 | |
); | |
$new_src = add_query_arg($params, $src); | |
$iframe = str_replace($src, $new_src, $iframe); | |
// Add extra attributes to iframe HTML. | |
$html = str_replace('frameborder="0"', 'frameborder="0" allow="accelerometer; autoplay; muted; encrypted-media; gyroscope; picture-in-picture"', $iframe); | |
// Display customized HTML. | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment