Skip to content

Instantly share code, notes, and snippets.

@yhira
Last active April 21, 2018 02:34
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 yhira/a0ec26b5bf747ac8cf9a9158a04634f6 to your computer and use it in GitHub Desktop.
Save yhira/a0ec26b5bf747ac8cf9a9158a04634f6 to your computer and use it in GitHub Desktop.
CocoonのGist埋め込み機能のデモ
//gistのembed対応(WordPressのエディターにURLを入力するだけで利用できる)
wp_embed_register_handler( 'gist', '/https?:\/\/gist\.github\.com\/([a-z0-9]+)\/([a-z0-9]+)(#file=.*)?/i', 'wp_embed_register_handler_for_gist' );
if ( !function_exists( 'wp_embed_register_handler_for_gist' ) ):
function wp_embed_register_handler_for_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 );
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment