I like to prevent captions from being outputted in my custom gallery function. I could easily just hide it using CSS but it doesn't feel right.
The caption is being sent from media.php this line.
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption'>
" . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
I could just remove . wptexturize($attachment->post_excerpt) .
but as soon as I update its gone. Id like to to this without copying the whole gallery function.
Wordpress is generating the alt tag using the caption field, which is desired.
Is there a way?
My function code
function modified_gallery_shortcode( $attr ) {
$attr['size'] = "thumbnail";
$attr['link'] = "file";
$attr['itemtag'] = "";
$attr['icontag'] = "";
$attr['captiontag'] = "";
$output = gallery_shortcode( $attr );
$output = strip_tags( $output, '<a><img><li><p>' );
$from = array(
"class='gallery-item'",
"class='gallery-icon landscape'",
"a href=",
"class='wp-caption-text gallery-caption'"
);
$to = array(
"",
"",
"a class=\"swipebox\" rel=\"group\" href=",
"",
);
$output = str_replace( $from, $to, $output );
$output = sprintf( '<div class="gallery">%s</div>', $output );
return $output;
}
add_shortcode( 'gallery', 'modified_gallery_shortcode' );
I like to prevent captions from being outputted in my custom gallery function. I could easily just hide it using CSS but it doesn't feel right.
The caption is being sent from media.php this line.
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption'>
" . wptexturize($attachment->post_excerpt) . "
</{$captiontag}>";
}
I could just remove . wptexturize($attachment->post_excerpt) .
but as soon as I update its gone. Id like to to this without copying the whole gallery function.
Wordpress is generating the alt tag using the caption field, which is desired.
Is there a way?
My function code
function modified_gallery_shortcode( $attr ) {
$attr['size'] = "thumbnail";
$attr['link'] = "file";
$attr['itemtag'] = "";
$attr['icontag'] = "";
$attr['captiontag'] = "";
$output = gallery_shortcode( $attr );
$output = strip_tags( $output, '<a><img><li><p>' );
$from = array(
"class='gallery-item'",
"class='gallery-icon landscape'",
"a href=",
"class='wp-caption-text gallery-caption'"
);
$to = array(
"",
"",
"a class=\"swipebox\" rel=\"group\" href=",
"",
);
$output = str_replace( $from, $to, $output );
$output = sprintf( '<div class="gallery">%s</div>', $output );
return $output;
}
add_shortcode( 'gallery', 'modified_gallery_shortcode' );
if you can do it easy way ,so why not?
you can use jquery to do it like:
( function( $ ) {
function function_name() {
$( '.gallery-caption').css({display:'none'});
}
function_name();
} )( jQuery );