Skip to content

Instantly share code, notes, and snippets.

@jazzsequence
Last active April 20, 2017 21:51
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 jazzsequence/3ec37cec0781d302f5cfe8d7ec9267e7 to your computer and use it in GitHub Desktop.
Save jazzsequence/3ec37cec0781d302f5cfe8d7ec9267e7 to your computer and use it in GitHub Desktop.
extract a shortcode parameter from a shortcode
<?php
// Get some post.
$post = get_post( 1 );
// Get the shortcode param from a shortcode named [my-shortcode] inside the post content.
preg_match( '/\[my-shortcode param="([a-zA-Z0-9]+)"\]/', $post->post_content, $matches );
if ( array_key_exists( 1, $matches ) ) {
$hash = $matches[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment