Created
July 5, 2012 04:44
-
-
Save topdown/3051438 to your computer and use it in GitHub Desktop.
Gist URL in WP Post
This file contains 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
<?php | |
/** | |
* This allows you to simply post a gist url in a WordPress 3.0+ post and it grabs the actual gist and displays it | |
* For example, if your having issues or don't allow posting of embedded javascript, which should not be allowed | |
* | |
* Put this code in your theme functions file | |
* then post a gist url on a new line | |
* | |
* https://gist.github.com/1697338 | |
* | |
*/ | |
wp_embed_register_handler( 'gist', '#https://gist.github.com/([a-zA-Z0-9]+)(\#file_(.+))?$#i', 'wp_embed_handler_gist' ); | |
/** | |
* @param array $matches | |
* @param array $attr | |
* @param string $url | |
* @param $rawattr | |
* | |
* @return mixed|void | |
* @see http://codex.wordpress.org/Function_Reference/wp_embed_register_handler | |
*/ | |
function wp_embed_handler_gist( $matches, $attr, $url, $rawattr ) { | |
$embed = sprintf( | |
'<script src="https://gist.github.com/%s.js%s"></script>', | |
esc_attr($matches[1]), ''); | |
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