Skip to content

Instantly share code, notes, and snippets.

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 vladimirlukyanov/b345b6c84d4594ce1e485371864e2432 to your computer and use it in GitHub Desktop.
Save vladimirlukyanov/b345b6c84d4594ce1e485371864e2432 to your computer and use it in GitHub Desktop.
Extract values from shortcode WordPress
<?php
$shortcode = '[gallery id="123"]' // Sample shortcode
preg_match_all( '/' . get_shortcode_regex() . '/s', $shortcode, $matches ); //
$out = array();
if ( isset( $matches[2] ) ) {
foreach ( (array) $matches[2] as $key => $value ) {
if ( 'av_product_small_info' === $value ) { // Shortcode name
$out = shortcode_parse_atts( $matches[3][ $key ] );
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment