Skip to content

Show captions under thumbnails and single images

Sunshine Photo Cart takes advantage of WordPress' ability to import EXIF metadata when an image is uploaded to your client gallery. Data like keywords, caption, camera, and much more data you can see here gets imported into the database. Once in the database, you can then display this information with any image in a Sunshine Photo Cart gallery.

By default, the image file name is shown with the image when this option is enabled. If the "title" is present in the EXIF metadata, then that is shown instead. With the code snippets below, you can customize what name is shown for an image within your WordPress client galleries:

Show caption with thumbnails

Sunshine Photo Cart has an option to show the image name under the thumbnails in the Gallery view. In Sunshine > Settings > Sunshine > Show Image Data, select "Filename" or "Title".

The following code uses the "sunshine_image_name" filter and if a caption exists it replaces the default display to be displayed with the caption.

// Show caption under thumbnail
add_filter( 'sunshine_image_name', 'sunshine_thumbnail_show_caption', 10, 2 );
function sunshine_thumbnail_show_caption( $caption, $image ) {
	if ( ! empty( $image->get_data_value( 'post_excerpt' ) ) ) {
		$caption = $image->get_data_value( 'post_excerpt' );
	}
	return $caption;
}

Learn how to add this custom code to your WordPress website

Show caption under single image view

Each image in your gallery has it's own URL with the image displayed and various options. You can include the caption on this page below the image with the following custom code:

// Show caption on single image page
add_filter( 'sunshine_after_image', 'sunshine_image_show_caption', 10 );
function sunshine_image_show_caption( $image ) {
	if ( ! empty( $image->get_data_value( 'post_excerpt' ) ) ) {
		echo $image->get_data_value( 'post_excerpt' );
	}
}

Learn how to add this custom code to your WordPress website

Still need help?

If you have not yet found your answer in the documentation articles, please contact support