Remove Captions from Custom Gallery function.php

Question

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' );
0
, , rgfx 3 years 2020-06-02T02:10:53-05:00 0 Answers 92 views 0

Leave an answer

Browse
Browse