-1

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' );
  • what is the full code of your custom gallery function? – Michael Aug 3 '14 at 15:09
  • Why can't you just set captiontag=""? – user27457 Aug 3 '14 at 17:08
  • @MagentaCuda I tried but it still spits out the the caption text in question marks " caption text " – rgfx Aug 3 '14 at 17:27
  • 1
    Also, could some other plugin be doing an additional add_shortcode( 'gallery', ... ) after yours and overriding yours. I really don't understand why setting captiontag = "" doesn't work unless I am reading the wrong source code. By the way what is your WordPress version number. I am looking at 3.9 source code. – user27457 Aug 3 '14 at 22:53
  • 1
    @MagentaCuda Your right, I was using a template called bones that added its own filter to strip out gallery styles. I removed it and add this add_filter( 'use_default_gallery_style', '__return_false' ); and my problem is fixed. Thanks for your help, I prob would of never figured it out if it wasn't for you. – rgfx Aug 4 '14 at 5:05
0

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 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.