WordPress show Gallery Title and Captions

Question

I would like to show the gallery title together with the captions. Below is my attempt, but I keep getting Notice: Trying to get property of non-object . I still can’t figure it out what went wrong.

single.php

<div class="gallery-content">
        <?php 
        add_filter( 'shortcode_atts_gallery', 'fullsize_gallery' );     
        if( has_shortcode( $post->post_content, 'gallery' ) ) :   

        $gallery = get_post_gallery_images( $post->ID );

        $image_list = '<ul class="galleryslider" style="display: none;">'; 

        foreach( $gallery as $image ) :
        $image_title = wp_get_attachment_url($image->post_title);
        $image_caption = wp_get_attachment_url($image->post_excerpt);
        // Loop through each image in each gallery
        $image_list .= '<li><a href="'. $image . '" data-lightbox="'.$post->ID.'"><img src="' . $image . '" title="'.$image_title.'"/>'.$image_caption.'</a></li>';
        endforeach; 
        $image_list .= '</ul>';                     
        echo $image_list;                           
        endif;
        ?>
    </div><!-- .gallery-content -->

functions.php

function fullsize_gallery( $out )
{
    remove_filter( current_filter(), __FUNCTION__ );
    $out['size'] = 'full';
    return $out;
}
0
KC Chai 3 years 2020-04-06T12:53:42-05:00 0 Answers 72 views 0

Leave an answer

Browse
Browse