Created
February 26, 2016 00:19
-
-
Save ericakfranz/16e55308c42aaaa572bd to your computer and use it in GitHub Desktop.
Display image filename (without the extension) as the Caption.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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