Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

3 Answers 3

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

e.g.

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

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

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

share|improve this answer

Your Answer

 
discard

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.