Skip to content

Instantly share code, notes, and snippets.

@ericakfranz
Created February 26, 2016 00:19
Show Gist options
  • Save ericakfranz/16e55308c42aaaa572bd to your computer and use it in GitHub Desktop.
Save ericakfranz/16e55308c42aaaa572bd to your computer and use it in GitHub Desktop.
Display image filename (without the extension) as the Caption.
<?php
/**
* Plugin Name: Envira Gallery - Set Captions to Image Filenames (without extension)
* Plugin URI: http://enviragallery.com
* Version: 1.1
* Author: Erica Franz
* Author URI: https://fatpony.me
* Description: Sets Envira Gallery Captions to their image filenames without the file extension
*/
function envira_set_captions_image_filenames( $data ) {
// Iterate through each gallery image
foreach ( $data['gallery'] as $key => $item ) {
$filename = $item['src'];
$data['gallery'][ $key ]['caption'] = basename( preg_replace('/\\.[^.\\s]{3,4}$/', '', $filename) );
}
return $data;
}
add_filter( 'envira_gallery_pre_data', 'envira_set_captions_image_filenames' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment