Last active
March 4, 2022 16:48
-
-
Save khleomix/c64b29b3416a010e0413db53d22c4c67 to your computer and use it in GitHub Desktop.
Vimeo Background
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 | |
/** | |
* Shortcode to display Vimeo video. | |
* | |
* @param array $args Parameters include vimeo_id and more. | |
* @author JC Palmes | |
*/ | |
function embed_vimeo_video( $args = [] ) { | |
// Set defaults. | |
$defaults = [ | |
'vimeo_id' => '', | |
]; | |
// Parse args. | |
$args = wp_parse_args( $args, $defaults ); | |
// If field contains URL, get the ID. | |
if ( false !== strripos( $args['vimeo_id'], 'http' ) ) { | |
$regex = '/(https?:\/\/)?(www\.)?(player\.)?vimeo\.com\/([a-z]*\/)*([0-9]{6,11})[?]?.*/'; | |
preg_match( $regex, $args['vimeo_id'], $m ); | |
$args['vimeo_id'] = $m[5]; | |
} | |
?> | |
<iframe src="https://player.vimeo.com/video/<?php echo esc_attr( $args['vimeo_id'] ); ?>" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen class="wistia_embed wistia_async_<?php echo esc_attr( $args['vimeo_id'] ); ?> aspect-image contain"></iframe> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment