Last active
April 20, 2017 21:51
-
-
Save jazzsequence/3ec37cec0781d302f5cfe8d7ec9267e7 to your computer and use it in GitHub Desktop.
extract a shortcode parameter from a shortcode
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 | |
// 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