Skip to content

Instantly share code, notes, and snippets.

@AlexanderOMara
Created June 5, 2015 19:44
Show Gist options
  • Save AlexanderOMara/aa28679c2182055e7539 to your computer and use it in GitHub Desktop.
Save AlexanderOMara/aa28679c2182055e7539 to your computer and use it in GitHub Desktop.
do_shortcode inside shortcode
/*
Parses shortcodes inside shortcodes by passing the content into do_shortcode.
[testouter][testinner][/testinner][/testouter]
*/
function shortcode_test_outer( $atts, $content = null ) {
?><p>shortcode-outer-start</p><?php
do_shortcode( $content );
?><p>shortcode-outer-end</p><?php
}
add_shortcode( 'testouter', 'shortcode_test_outer' );
function shortcode_test_inner( $atts, $content = null ) {
?><p>shortcode-inner-start</p><?php
do_shortcode( $content );
?><p>shortcode-inner-end</p><?php
}
add_shortcode( 'testinner', 'shortcode_test_inner' );
/*
Parses a hardcoded shortcode inside another shortcode by passing the shortcode string to do_shortcode.
[testouter][/testouter]
*/
function shortcode_test_outer( $atts, $content = null ) {
?><p>shortcode-outer-start</p><?php
do_shortcode( '[testinner][/testinner]' );
?><p>shortcode-outer-end</p><?php
}
add_shortcode( 'testouter', 'shortcode_test_outer' );
function shortcode_test_inner( $atts, $content = null ) {
?><p>shortcode-inner-start</p><?php
?><p>shortcode-inner-end</p><?php
}
add_shortcode( 'testinner', 'shortcode_test_inner' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment