Category Archives: php

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

 

Random posts WordPress plug-in as random image gallery generator

I was helping to customize one WordPress blog and there was desire to have sidebar gallery with random picture from the post that would link to the post. We were using Popular posts plug-in already, so we decided to use Random posts plug-in. The problem we encountered was with the posts, that did not contain any image. This resulted in empty square in place of the image. Not nice. I know, we should use dedicated plug-in, but …

Continue reading