WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Imagine this basic shortcode in your functions.php file:

function div_shortcode( $atts ) {
   return '<div class="div"></div>';

add_shortcode('div', 'div_shortcode');

So every [div] in Wordpress editor gives <div class="div"></div>.

Everything looks and works fine, right?

Now here comes the trouble.

I need to use my shortcode in PHP file (not putting it via WP Text Editor).

Luckily there's a function for that:

<?php do_shortcode('[div]'); ?> 

But, wait, it shows... nothing?

<?php do_shortcode('[gallery]'); ?> 

Even this one doesn't work.

Why is that happening? Any ideas?

share|improve this question
up vote 7 down vote accepted

The shortcode functions just return a value, you need to echo or assign it to something.

<?php echo do_shortcode('[div]'); ?>
share|improve this answer
Christ, I've tried it before and nothing. But today it works. Stupid typos! Thank you so much! :) – Wordpressor Jun 2 '11 at 8:10

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.