Show keywords for an image
When you include keywords within the metadata of an image (using Lightroom, Adobe Bridge, or your favorite image manager software), they are saved and searchable by default in Sunshine Photo Cart. In the below code example, you can also show all the keywords on the single image view. You can also show all the EXIF metadata.
add_action( 'sunshine_after_image', 'sunshine_show_image_keywords' );
function sunshine_show_image_keywords( $image ) {
$metadata = $image->get_meta_value( '_wp_attachment_metadata' );
if ( ! empty( $metadata['image_meta']['keywords'] ) ) {
echo join( ', ', $metadata['image_meta']['keywords'] );
}
}
Learn how to add this custom code to your WordPress website
Showing keywords in lightbox
If you are using the Lightbox add-on and want to show the keywords there as well, you need to include this additional code snippet which appends the keywords to where the filename is shown at the bottom:
add_filter( 'sunshine_lightbox_image_name', 'sunshine_lightbox_image_name_keywords', 10, 2 );
function sunshine_lightbox_image_name_keywords( $name, $image ) {
$metadata = $image->get_meta_value( '_wp_attachment_metadata' );
if ( ! empty( $metadata['image_meta']['keywords'] ) ) {
$name .= ' (' . join( ', ', $metadata['image_meta']['keywords'] ) . ')';
}
return $name;
}
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