Nested shortcode wordpress

Posted: September 9, 2014 in web

to use: [div][vid][/vid][/div]

...
function __construct() {
        add_shortcode('div', array($this, 'sc_div'));
        add_shortcode('vid', array($this, 'sc_video'));
    }

    function sc_div($atts, $content = null) {
        $a = shortcode_atts(array(
            'class' => 'px1',
            'style' => '',
                ), $atts);
        return '<div class="'.$a['class'].'">'.do_shortcode($content).'</div>';
    }
    function sc_video($atts) {
        $a = shortcode_atts(array(
            'class' => 'px2',
            'style' => '',
                ), $atts);
        return $a['class'];
    }
...
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s