WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Gallery Short Code (3 posts)

  1. Robert Dall
    Member
    Posted 2 years ago #

    I would rather have a gallery short code that could display the title of the image rather then the caption below the image. As captions can be a couple sentences sometimes when you use the thumbnail image for the gallery the caption seems almost as large as the thumbnail image itself.

    When you look at the media 'wp-includes/media.php' it only give you one option which is the caption.

    Of course I can just display the CSS to none and it won't show anything below the image, but I believe their could be better solutions.

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    you can add your own gallery shortcode to functions.php of your theme, starting with a copy of the code from wp_includes/media.php;

    remove_shortcode('gallery', 'gallery_shortcode');
    add_shortcode('gallery', 'rdall_gallery_shortcode');
    function rdall_gallery_shortcode($attr) {
    HERE ADD THE FULL GALLERY CODE FROM MEDIA.PHP, BUT CHANGE THESE LINES:
    		if ( $captiontag && trim($attachment->post_title) ) {
    			$output .= "
    				<{$captiontag} class='wp-caption-text gallery-caption'>
    				" . wptexturize($attachment->post_title) . "
    				</{$captiontag}>";
    HERE THE REST OF THE CODE
    return $output;
    }

    the full section in one bit:
    http://pastebin.com/uaLJbDsi

  3. Robert Dall
    Member
    Posted 2 years ago #

    Thanks Alchymyth! that looks awesome! I will certainly throw this into the function file and check it out!

Topic Closed

This topic has been closed to new replies.

About this Topic