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?

1 Answer 1


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

<?php echo do_shortcode('[div]'); ?>
  • Christ, I've tried it before and nothing. But today it works. Stupid typos! Thank you so much! :) Jun 2, 2011 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.