• This is my shortcode:

    function add_div($atts, $content = null) {
    	$class = shortcode_atts( array('class' => 'default_class'), $atts );
    	return '<div class="'.$class['class'].'">'.$content.'</div>';
    }
    add_shortcode("add_div", "add_div");

    I’m trying to use this on page template:
    <? echo do_shortcode('[add_div class="some_class"]Some text[/add_div]'); ?>

    And it return something like that:

    <div class="some_class"></div>
    CONTENT GOES HERE

    I want it to make it like this:
    <div class="some_class">CONTENT GOES HERE</div>

    The problem is that it doesn’t parse [/add_div] element.

    It makes it correct (it parses [/add_div]) when my shortcode is placed on some page or in post but it doesn’t work in template file.
    Please help!

Viewing 1 replies (of 1 total)
  • Just a guess, but couldn’t you do something like this:

    <?php
    echo do_shortcode('[add_div class="some_class" content="Some text"]');
    ?>

    Take a look at the ‘extract’ in Shortcode_API

Viewing 1 replies (of 1 total)

The topic ‘do_shortcode() problem (or bug)’ is closed to new replies.