I'm using Wordpress as a CMS for a small business website (not my first choice.) Each product page needs to have a small carousel of images that contains images relevant to the product.

I've set up a custom Post Type for the products and am currently using custom fields to display some information specific to each product. I can't just cut and paste the code for each individual carousel into a custom fields; since, to get the images properly, I need PHP in the code for the carousel.

I also can't use individual custom fields for each image since the number of images in the carousel could be unpredictable.

Is there a good way to do this? Suggestions are appreciated!

1 Answer 1


You can use WordPress built in gallery, see Gallery Shortcode. If you look for the gallery shortcode function in WordPress core, you can see how it grabs the image attachments to a post with get_children and outputs them. You can use this as a starting point to write your own function to output the gallery with your own markup and css / js by filtering post_gallery or just ouputting attached images without adding the gallery shortcode to the content.

There are also numerous gallery plugins, some have support for slider scripts. If you search the plugin repository you'll find a few.

Edit- there's also no reason why you can't store n number of images as multiple custom fields with the same key. you'll get an array of images, you just won't be able to manage the order easily. another option is to create your own meta box and manage an array of images yourself using a single custom field. There are a few questions on this site regarding managing images with your own meta box + media library if you search around.

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.