Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Last active October 10, 2015 22:58
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 jaredatch/3764510 to your computer and use it in GitHub Desktop.
Save jaredatch/3764510 to your computer and use it in GitHub Desktop.
Detect gist shortcode in post content
<?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