Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Created February 25, 2014 22:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasgriffin/9219422 to your computer and use it in GitHub Desktop.
Save thomasgriffin/9219422 to your computer and use it in GitHub Desktop.
Add the image title as a caption below the image in the gallery display.
<?php
add_filter( 'envira_gallery_output_after_link', 'tgm_envira_gallery_caption', 10, 5 );
/**
* Adds a caption below each image in the gallery.
*
* @since 1.0.0
*
* @param string $output String of gallery output.
* @param mixed $id The ID of the gallery.
* @param array $item Array of data about the image.
* @param array $data Array of gallery data.
* @param int $i The current index in the gallery.
* @return string $output Amended string of gallery output.
*/
function tgm_envira_gallery_caption( $output, $id, $item, $data, $i ) {
if ( ! empty( $item['title'] ) ) {
$caption = '<div class="envira-gallery-captioned-data">';
$caption .= '<p class="envira-gallery-captioned-text">';
$caption .= $item['title'];
$caption .= '</p>';
$caption .= '</div>';
$caption = apply_filters( 'envira_gallery_themes_captioned_output', $caption, $id, $item, $data, $i );
return $output . $caption;
}
// Return the output.
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment