Support » Themes and Templates » How to number an image gallery

  • Resolved sentineltravis


    Is there a way or modification to put numbers on the images within a post? A small number being displayed at the top of the image like they have at is close to what I am looking for

    Signs full of ‘WTF’ (37 Photos)

    I have tried inputting code from into my functions.php:

    I believe line 108 outputs the number:
    $output .= “<div class=’imageNum’><span>”.($i+1).”</span></div>”; //NEW

    I am rather new to coding and any help is greatly appreciated!

Viewing 15 replies - 1 through 15 (of 16 total)
  • Hello,

    You could use the default caption functionality of the WordPress gallery. You can then enter the images numbers as captions and style them the way you want using CSS 🙂

    I just added the code from the pastebin into my test site (into functions.php of a child theme of Twenty Twelve) and it is working –

    however, there could be a conflict with other filters or plugins, and the location and visibility of the numbers might depend on the css of your theme

    – please post a link to one of your posts or pages with a gallery.


    Did you just paste the code at the bottem of functions.php? Below is a link to a post on my test site.

    Thank you for the responses.

    your link seems to show a post with a lot of images, but no image gallery;

    I will test again using info provided and let you know either way! thank you again


    I was able to get the result in another test post listed below.

    Would you happen to know if there is a way to set the images to be their full size and centered?

    Also previously we were linking the first image to the post then using the “more” feature so that only one image was displayed on the home page.

    we are currently using the [gallery link="file" columns="1" orderby="title"] code from the codex link you sent.

    to set the images to be their full size and centered?

    about full size:
    try to integrate the size parameter into your gallery shortcode:

    [gallery size="full"]

    to center the image, you will need to change the code and css;

    the needed css is in these three styles:

    .imageNum span{text-align:center;padding:3px;}

    you might need to adjust the top:0px;left:0px; number values.

    new code:

    – the number code got moved into the .gallery-icon element for better positioning.

    That is working perfect. The only issue is the display on the home page.

    You can see what I am trying to accomplish @
    Is there a way to link the fist image from the gallery to be the only image appearing on the home page post then have the “view more” link underneath?

    Or possibly just insert the image file and use “view more” and code to hide them once inside the full post?

    Is there a way to link the first image from the gallery to be the only image appearing on the home page post then have the “view more” link underneath?

    you could use a conditional in functions.php which checks for !is_singular() to break the output loop of the gallery images;


    $output .= "</{$itemtag}>";
    		if ( $columns > 0 && ++$i % $columns == 0 )
    			$output .= '<br style="clear: both" />';
    //break the foreach loop on index pages
    if( !is_singular() ) break;
    //breaks the foreach loop on index pages	
    	$output .= "
    			<br style='clear: both;' />";
    	$output .= "	</div>\n";
    //add 'read-more' on index pages
    if( !is_singular() ) $output .= "<p style='text-align:center;width:100%;'><a href='" . get_permalink($post->ID) . "#" . $post->ID . "'>View Full Gallery</a></p>";
    //adds the 'read more' on index pages
    	return $output;

    – this replaces a section at the and of the shortcode starting with the three first lines which are unedited;

    – the full code is in

    You’re a genius. Im so donating to the paypal on your site!

    last question is if there is a way to remove the 1 from only the home page?

    I feel like such a bug.
    can the image on the home page be set to link into the post? currently when clicked it links to only the imagefile instead of entering the post

    single gallery image in index pages linked to post, number 1 removed from single image;


    Thank you thank you. You are a genius and your help is very much appreciated.

    @alchymyth – I’m trying to find the location of the code “<br style=’clear: both;’ />” in the 2012 theme as relates to galleries.

    I’m using the built-in WP media gallery and it’s adding 2 of these returns making a very large bottom margin.

    I’ve trying lots of work-arounds but I think I like to remove it from the code unless it’s in the core.

    Any help would be really appreciated – thanks!

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘How to number an image gallery’ is closed to new replies.