Skip to content

Instantly share code, notes, and snippets.

@jdoubleu
Created July 1, 2016 13:00
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 jdoubleu/e581a077fe20aceb16999965907389e4 to your computer and use it in GitHub Desktop.
Save jdoubleu/e581a077fe20aceb16999965907389e4 to your computer and use it in GitHub Desktop.
Get attributes of child shortcodes in parent.
<?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