WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wonder if it's possible to do a shortcode only in another shortcode. For example I got following code pieces:

[heading]some pricing page[/heading]
  [heading]Some title[/heading]

Now I don't want to define one shortcode heading which would apply to both the nested one and the first level shortcode. I want the both heading shortcodes to produce different outputs. Of course, I could try to solve this by renaming one of the shortcodes to title or something, but this doesn't always result in optimal naming arrangements.

share|improve this question
up vote 2 down vote accepted

To use a different callback for the nested headings switch the shortcode handler in the pricing_box callback and restore the main handler before you return the string.

add_shortcode( 'pricing_box', 'shortcode_pricing_box' );
add_shortcode( 'heading',     'shortcode_heading_main' );

function shortcode_pricing_box( $atts, $content = '' )
    // switch shortcode handlers
    add_shortcode( 'heading', 'shortcode_heading_pricing_box' );

    $out = '<div class="pricing-box">' . do_shortcode( $content ) . '</div>';

    // restore main handler
    add_shortcode( 'heading', 'shortcode_heading_main' );

    return $out;

function shortcode_heading_main( $atts, $content = '' )
    return "<h2>$content</h2>";

function shortcode_heading_pricing_box( $atts, $content = '' )
    return "<h3>$content</h3>";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.