Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@websupporter
Last active March 16, 2016 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save websupporter/36d1108d03c3cdab5d3d to your computer and use it in GitHub Desktop.
Save websupporter/36d1108d03c3cdab5d3d to your computer and use it in GitHub Desktop.
This script adds Github Gist to the registered oEmbed providers in WordPress
<?php
/**
* This script adds Github Gist to the registered oEmbed providers in WordPress
**/
wp_embed_register_handler( 'gist', '/https:\/\/gist\.github\.com\/(.*)\/(.*)\/?/i', 'wp_embed_handler_gist' );
function wp_embed_handler_gist( $matches, $attr, $url, $rawattr ) {
$embed = sprintf(
'<script src="https://gist.github.com/%1$s/%2$s.js"></script>',
esc_attr($matches[1]),
esc_attr($matches[2])
);
return apply_filters( 'embed_gist', $embed, $matches, $attr, $url, $rawattr );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment