Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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