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 have a post with image gallery, it has 10 images. Can I get the direct link to the images in the post, so that I can display first 5 images on the homepage?

share|improve this question

You could use this loop for fetching the images from current post.

$images = get_posts(array(
    'post_parent' => get_the_ID(),
    'post_type' => 'attachment',
    'posts_per_page' => 5,
    'post_mime_type' => 'image'

if( $image ) {
    foreach($images as $image) :
        echo wp_get_attachment_link( $image->ID, 'thumbnail-size', true );


  1. wp_get_attachment_link
  2. wp_get_attachment_image
share|improve this answer

Add this to your child themes functions file and change the image I.D's to match the ones you want included in the gallery.

add_action( 'wp_head', 'wpsites_front_page_gallery' );
function wpsites_front_page_gallery() {
if ( is_home() ) {
echo do_shortcode('[gallery columns="5" link="file" ids="45266,45258,45250,45229,45227" orderby="rand"]');

enter image description here

Change the wp_head hook to any WordPress or theme specific hook for positioning.

share|improve this answer

If you are using Next Gen Gallery you can then install an additional plugin which allows widgets http://wordpress.org/extend/plugins/nextgen-gallery-sidebar-widget/

If you are using WordPress own Image Library and Gallery function try this plugin http://wordpress.org/extend/plugins/fx-gallery-widget/

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.