Skip to content

Instantly share code, notes, and snippets.

@morgyface
Created August 27, 2019 14:30
Show Gist options
  • Select an option

  • Save morgyface/5f243b6bb74491e4e228ac96dc684381 to your computer and use it in GitHub Desktop.

Select an option

Save morgyface/5f243b6bb74491e4e228ac96dc684381 to your computer and use it in GitHub Desktop.
ACF oEmbed | Adding color param to vimeo videos
<?php
// Project specific function that strips out parameters on a vimeo URL and adds a color param
function add_color_to_vimeo( $iframe ) {
if( strpos($iframe, 'vimeo') !== false ) { // Does the iframe contain vimeo
preg_match('/src="(.+?)"/', $iframe, $matches); // Finds the src element of the iframe
$src = $matches[1];
$clean_src = strtok($src, '?'); // Removes all parameters
$new_params = array(
'color' => 'FEE600' // New color parameter
);
$new_src = add_query_arg( $new_params, $clean_src ); // Adds new params to clean src
$iframe = str_replace($src, $new_src, $iframe); // Reassembles the iframe
}
return $iframe;
}
?>
@morgyface
Copy link
Author

Add color to vimeo videos

I was finding that the ACF oEmbed output was adding new unnecessary parameters that were rendering the color parameter ineffective when I added it. This function extracts the iframe source, removes all the parameters, adds the color parameter and then reassembles the full iframe.

If the embed doesn't contain vimeo it will simply pass through the function unaltered.

Worked for me as of August 2019.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment