Last active
September 1, 2016 21:09
-
-
Save vladimirlukyanov/b345b6c84d4594ce1e485371864e2432 to your computer and use it in GitHub Desktop.
Extract values from shortcode WordPress
This file contains hidden or 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 | |
$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