Skip to content

Instantly share code, notes, and snippets.

@khleomix
Last active March 4, 2022 16:48
Show Gist options
  • Save khleomix/c64b29b3416a010e0413db53d22c4c67 to your computer and use it in GitHub Desktop.
Save khleomix/c64b29b3416a010e0413db53d22c4c67 to your computer and use it in GitHub Desktop.
Vimeo Background
<?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