Modify default gallery behavior – display image’s title instead of it’s caption

I was asked to change default behavior of gallery in WordPress so it displays image’s title except it’s caption inside the gallery placed into the post or page. On the attachment page (image page) it should still show it’s caption as caption.

Simple solution that worked for me was to modify “wordpress/wp-includes/media.php” file at line 1068-1072 and change “post_excerpt” to “post_title”.

Before:

        if ( $captiontag && trim($attachment->post_excerpt) ) {
            $output .= "
                <{$captiontag} class='wp-caption-text gallery-caption'>
                " . wptexturize($attachment->post_excerpt) . "
                </{$captiontag}>";
        }

After:

        if ( $captiontag && trim($attachment->post_title) ) {
            $output .= "
                <{$captiontag} class='wp-caption-text gallery-caption'>
                " . wptexturize($attachment->post_title) . "
                </{$captiontag}>";
        }

Now it shows image’s title instead of it’s caption. If you know about better solution, let me know.

Source:

http://wordpress.org/support/topic/display-title-as-the-caption-wordpress-gallery

http://wordpress.org/support/topic/display-title-as-caption-in-wp-gallery

 

Leave a Reply

Your email address will not be published. Required fields are marked *