• Resolved dhirlinger

    (@dhirlinger)


    In the process of creating a child theme from twenty fourteen, I created additional caption information for images using the img_caption_shortcode hook. This added content displays in the caption area for attached images that are not part of a gallery, however gallery images remain unaffected and contain only the default caption shortcode output. Does img_caption_shortcode affect gallery images? If not, how does one filter gallery caption output? Thanks in advance for any help.

    My code:

    add_filter( 'img_caption_shortcode', 'my_img_caption_shortcode', 10, 3 );
    
    function my_img_caption_shortcode( $empty, $attr, $content ){
    	$geez = get_post_type($post);
    
    $atts = shortcode_atts( array(
    		'id'	  => '',
    		'align'	  => 'alignnone',
    		'width'	  => '',
    		'caption' => '',
    		'class'   => '',
    	), $attr, 'caption' );
    
    	$atts['width'] = (int) $atts['width'];
    	if ( $atts['width'] < 1 || empty( $atts['caption'] ) )
    		return $content;
    
    	if ( ! empty( $atts['id'] ) )
    		$atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" ';
    
    	$class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] );
    
    	$att_id = $attr['id'];
    	$att_id = str_replace('attachment_', '', $att_id);
    	$dpi = get_post_meta($att_id, '_custom1', true);
    
    		if ( current_theme_supports( 'html5', 'caption' ) & $geez == 'epk' ) {
    			return '<figure ' . $atts['id'] . 'style="width: ' . (int) $atts['width'] . 'px;" class="' . esc_attr( $class ) . '">'
    			. do_shortcode( $content ) . '<figcaption class="wp-caption-text">' . $atts['caption'] . '</figcaption><div class="dpi-link-wrap><a class="dpi-link" href="' . esc_url( $dpi ) . '" download>download hi-res 300dpi image here</a></div></figure>';
    		}
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dhirlinger

    (@dhirlinger)

    I should add that I’m using get_post_gallery(false) to display the gallery in question with the loop:

    if ( get_post_gallery(false) ) :
            echo get_post_gallery(false);
    endif;

    Thread Starter dhirlinger

    (@dhirlinger)

    …and the answer is no. Use the gallery shortcode filter.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Does img_caption_shortcode affect gallery images?’ is closed to new replies.