Last active
December 30, 2015 16:19
-
-
Save mitchmccline/7853780 to your computer and use it in GitHub Desktop.
WordPress CodePen Quick Link Embed - WP Embed Register Handler for CodePen embedded pens in posts from the pen url that is pasted into the wp editor. Using regex to pull the username and pen id slug hash from any CodePen pen link in order to register the embed handler in WordPress. http://codex.wordpress.org/Function_Reference/wp_embed_register_…
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
/** | |
* | |
* Creates an Embed Handler for CodePen Embeds | |
* Tested on WP 3.7.1 | |
* | |
*/ | |
wp_embed_register_handler( 'codepen', '/http?:\/\/codepen\.io\/([a-z0-9]+)\/pen\/([a-z0-9]+)/i', 'wp_embed_handler_codepen'); | |
function wp_embed_handler_codepen( $matches, $attr, $url, $rawattr ) { | |
$embed = sprintf( | |
'<p data-height="268" data-theme-id="0" data-user="%1$s" data-slug-hash="%2$s" data-default-tab="result" class="codepen"><a href="http://codepen.io/%1$s/pen/%2$s">A Pen by %1$s</a> (<a href="http://codepen.io/%1$s">@%1$s</a>) on <a href="http://codepen.io">CodePen</a></p> | |
<script async src="//codepen.io/assets/embed/ei.js"></script>', | |
esc_attr($matches[1]), | |
esc_attr($matches[2]) | |
); | |
return apply_filters( 'embed_codepen', $embed, $matches, $attr, $url, $rawattr ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment