Created
August 27, 2019 14:30
-
-
Save morgyface/5f243b6bb74491e4e228ac96dc684381 to your computer and use it in GitHub Desktop.
ACF oEmbed | Adding color param to vimeo videos
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
| <?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; | |
| } | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
vimeoit will simply pass through the function unaltered.Worked for me as of August 2019.