0

I am using a simple Wp 5.x gallery like this [gallery size="full" columns="1" ids="6304,6305,6306,6307,6308,6309"]

The gallery shows me the images and the captions/description after the image. How can I automatically insert/inject the gallery image title BEFORE this image captions/description?

See image expample attached

Thanks in advance wp 5.x gallery example

1 Answer 1

0

use this code in single.php

  $post->ID,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby'        => 'title',
        'order'           => 'ASC',
        'post_mime_type' => 'image',
    )))
    {
        foreach( $images as $image ) {
            $attachmenturl = wp_get_attachment_url($image->ID);
            $attachmentimage = wp_get_attachment_image_src( $image->ID, full );
            $imageDescription = apply_filters( 'the_description' , $image->post_content );
            $imageTitle = apply_filters( 'the_title' , $image->post_title );
            $i++;
            if (!empty($imageTitle)) {
                echo ' » '.$imageDescription.'';
} else { echo '' ; }
        }
    } else {
        echo 'No Image Found';
    }?>
1
  • Hi SauRav, thank you very much. I hired a programmer in 2020 to make this for me. But for another gallery I will use your code. Thank you
    – Waldemar
    Commented Aug 9, 2022 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.