I’d like to change only one output of native WP Gallery (in media.php)
On Smashing Magazine (link) author advises to change whole gallery_shortcode function.
But I wondered if is possible to change only specific output ($captiontag)
I wrote:
add_filter( 'captiontag', 'my_captiontag' );
function my_captiontag( $captiontag ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption'><p>
" . wptexturize($attachment->post_excerpt) . "
</p></{$captiontag}>";
}
but it doesn’t work 🙁
There are no filter hook called
captiontag
. You can change the value of the caption html tag by specifying thecaptiontag
option when inserting the[gallery]
shortcode.From the gallery shortcode codex page:
Update:
The following code will overwrite the default
[gallery]
output. It is basically a copy of thegallery_shotcode()
function with one modification to display the image title wrapped in<h3>
tag before the image:There is no need to copy the
gallery
shortcode. Just set your filter function between the native handlerâs output and the final output.To do that, hijack the shortcode handler, then run a
preg_replace_callback()
over the output.Similar posts