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

I'm making a homepage template for my theme and I want to call a plugin, namely royalslider. Surely

do_shortcode('[gallery id= "1"]');

Should do the trick?

share|improve this question
Is your homepage an actual post/page containing attached images? And you're calling do_shortcode inside the main loop? – Tom J Nowell Sep 25 '12 at 18:04
is that the official shortcode used by royalsider? – Michael Sep 25 '12 at 18:25
@TomJNowell Nope - it's just a home.php file. Can do_shortcode only be called in a loop? – Megh Sep 25 '12 at 18:25
@Michael Yes it is. – Megh Sep 25 '12 at 18:28
The gallery shortcode makes no sense without a post as its current context, you cant just call shortcodes anywhere, how would the gallery know what images to use? – Tom J Nowell Sep 25 '12 at 18:55

Ensure you have the preload skin option selected in the Royalslider options

share|improve this answer

do_shortcode() returns output and doesn't print anything. I'm often caught by this. Often the solution is to just echo the function's output:

echo do_shortcode('[gallery id="1"]');

You should also remove the space after id=.

Finally, make sure that you have images attached to the Post with the ID 1, which is what that shortcode would normally output.

share|improve this answer
Thanks, unfortunately it doesn't work. – Megh Sep 25 '12 at 18:51

do_shortcode needs to be called inside a post loop. Otherwise you're left with the problem of:

  • Which gallery
  • Which images
  • etc

You're using this plugin right? http://codecanyon.net/item/royalslider-touch-content-slider-for-wordpress/700256?ref=Semenov&ref=Semenov&clickthrough_id=84484598&redirect_back=true

I'd suggest you make your gallery in a post, and then have a post in a featured category, and display that ( with the shortcode in the content ). use a WP_Query loop with a limit of 1 post to prevent interfering with the main loop


<div id="featured-post">
    $q = new WP_Query('category_name' => 'featured','posts_per_page' => 1);
    } else {
        ?><p>no featured post found!</p><?php

This also gives you the extra flexibility of changing your mind or updating the slider, or using a static image, or having a text based feature

share|improve this answer

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.