Title: do_shortcode() problem (or bug)
Last modified: August 19, 2016

---

# do_shortcode() problem (or bug)

 *  [flow01](https://wordpress.org/support/users/flow01/)
 * (@flow01)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/do_shortcode-problem-or-bug/)
 * 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)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/do_shortcode-problem-or-bug/#post-1508833)
 * 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](http://codex.wordpress.org/Shortcode_API)

Viewing 1 replies (of 1 total)

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [MichaelH](https://wordpress.org/support/users/michaelh/)
 * Last activity: [15 years, 10 months ago](https://wordpress.org/support/topic/do_shortcode-problem-or-bug/#post-1508833)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
