0

I've created a gallery in a static page of my wordpress site, like this:

[gallery type="rectangular" ids="129,13,126,34,130"]

This page has ID=63, so I'm trying to display this gallery in my homepage with this line of code:

<?php echo do_shortcode("[gallery id='63']"); ?>

But nothing is shown...Am I missing anything?

Thanks in advance!

2
  • Yes, you should be using [gallery type="rectangular" ids="129,13,126,34,130"] instead of gallery id. Page ID is irrelevant
    – M-R
    Commented Feb 3, 2015 at 16:39
  • Or, make sure the images (129,13,126,34,130) are attached to Page ID "63". Page is not necessarily to have [gallery] shortcode in it.
    – M-R
    Commented Feb 3, 2015 at 16:51

1 Answer 1

0

While gallery shortcode does have id arguments, it won't do what you think.

If that argument is present WP will try to look for child attachments of that post, using get_children(). It won't take content of the post and shortcodes in it into account.

If the gallery is only content of that page you could try the following (not tested):

echo do_shortcode( get_post_field( 'post_content', 63 ) );
2
  • that seems right, is there any way of using this solution and also limiting the number of images shown? For example, just showing the last 20 images Commented Feb 3, 2015 at 20:43
  • Don't include them into shortcode? You are really stretching what it's meant for here. It might make sense to just store those IDs in some form (like an option) and take them from there.
    – Rarst
    Commented Feb 3, 2015 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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