Skip to content

Instantly share code, notes, and snippets.

@tzkmx
Created January 31, 2017 23:51
Show Gist options
  • Save tzkmx/215cf5537b7aee83d85c189ea744f2cf to your computer and use it in GitHub Desktop.
Save tzkmx/215cf5537b7aee83d85c189ea744f2cf to your computer and use it in GitHub Desktop.
Mini plugin to center Youtube iframes inserted with oEmbed in WordPress
<?php
/**
* @package Uploads_Media
* @version 0.1
* @see http://wordpress.stackexchange.com/a/50781/16301
*/
/*
Plugin Name: Center Youtube Iframe
Plugin URI: https://core.trac.wordpress.org/ticket/32920
Description: Wraps youtube iframe in a centered paragraph
Author: Jesus Franco
Version: 0.1
Author URI: https://tzkmx.wordpress.com/
*/
add_filter( 'embed_oembed_html', function( $cache, $url ) {
if( preg_match('/youtube.com/', $url) ) {
return '<p style="text-align:center;">' .$cache . '</p>';
}
return $cache;
}, 13, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment