Created
July 1, 2016 13:00
-
-
Save jdoubleu/e581a077fe20aceb16999965907389e4 to your computer and use it in GitHub Desktop.
Get attributes of child shortcodes in parent.
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 | |
// Currently in: Container | |
$mycontent = "Some content from before"; | |
// Attributes of Elements | |
$elements = array(); | |
// Register shortcode | |
add_shortcode('container_element', function($atts, $content) use(&$elements) { | |
$atts = shortcode_atts(array( | |
'prop1' => 1 | |
), $atts); | |
$atts['content'] = $content; | |
array_push($elements, $atts); | |
}); | |
// Run Shortcodes | |
do_shortcode($mycontent); | |
// Do Something with the elements | |
foreach($elements as $el) | |
echo $el['prop1']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment