Title: Enable shortcode in theme
Last modified: August 21, 2016

---

# Enable shortcode in theme

 *  [girll](https://wordpress.org/support/users/girll/)
 * (@girll)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/enable-shortcode-in-theme/)
 * Hi all. I am developing a wordpress theme, but I have a problem: I can’t use 
   shortcodes in my theme. I write:
 *     ```
       function display(){
        echo "Something";
       }
   
       add_shortcode('code', 'display');
       ```
   
 * It shows [code] in frontend.
    In my theme I am getting pages like this:
 *     ```
       <?php
       			$mypages = get_pages( array( 'post_type' => 'page') );
       			foreach( $mypages as $page ) {
       				$content = $page->post_content;
       				if ( ! $content )
       				$content = qtrans_use($lang, $content );
       				?>
       				<li id="<?php echo $page->post_name;?>">
       					<a href="#!/"> </a>
       					<div class="entry"><?php echo $content;?></div>
       				</li>
       				<?php
       			}
       		?>
       ```
   
 * What should I do make my theme support shortcodes.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [michalzuber](https://wordpress.org/support/users/michalzuber/)
 * (@michalzuber)
 * [12 years ago](https://wordpress.org/support/topic/enable-shortcode-in-theme/#post-4032516)
 * Try adding `<?php echo do_shortcode("[code]"); ?>` into your foreach.
 * [http://css-tricks.com/snippets/wordpress/shortcode-in-a-template/](http://css-tricks.com/snippets/wordpress/shortcode-in-a-template/)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years ago](https://wordpress.org/support/topic/enable-shortcode-in-theme/#post-4032517)
 * the correst way would be to apply the ‘the_content’ filter to the `$content` 
   string;
 * `<?php echo apply_filters( 'the_content', $content ); ?>`
 * however, already the posted shortcode function is wrong in ‘echo’ing the result
   instead of ‘return’ing it … [http://codex.wordpress.org/Shortcode_API](http://codex.wordpress.org/Shortcode_API)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Enable shortcode in theme’ is closed to new replies.

## Tags

 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * 2 replies
 * 3 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/enable-shortcode-in-theme/#post-4032517)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
