Last active
October 10, 2015 22:58
-
-
Save jaredatch/3764510 to your computer and use it in GitHub Desktop.
Detect gist shortcode in post content
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 | |
/** | |
* Detect gist shortcode in post content | |
* | |
* This assumes you are using a shortcode in the format [gist id="xxxxx']. | |
* I use this code in a custom metabox that is registered for my code snippets | |
* custom post type. This way after I save the snippet (or when editting an | |
* existing snippet) it will show the snippet below the post editor in a | |
* metabox. | |
* | |
* @author Jared Atchison | |
* @link http://jaredatchison.com/code/ | |
*/ | |
// Drop this inside your custom metabox | |
global $post; | |
if ( preg_match( '/\[gist[^\]]*\]/siU', $post->post_content, $matches ) ) { | |
if ( $matches[1] ) { | |
echo '<script src="https://gist.github.com/' . $matches[1] . '.js"> </script>'; | |
} | |
} else { | |
echo 'No gist detected.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment