Way to add captions to gallery images by code

I am creating posts by using wp_insert_post function. It works fine as I provide values in array required. Sometimes it is required to create a post having gallery. Without any problem, it also works fine.

But when there is requirement of adding captions to gallery images, I’m not able to add them programmatically. All captions are stored in an array.

Read More

Is there a way or hook to add them in gallery by code? Or in other way how to add caption array element beneath each image of gallery?

Related posts

Leave a Reply

1 comment

  1. you can change caption programmatically by jquery something like this:

    ( function( $ ) {    
        function function_name() {
              $( '#gallery-<gallery_ID>-<image_ID>').text("new caption");
    }
    
    function_name();
    } )( jQuery );