I want to add numbering to each image when I insert them into the post.
For example if I insert 3 images into a post, there will be:

  1. Image 1

  2. Image 2

  3. Image 3

I looked through the WordPress documentation, but I can’t find which hook is triggered when inserting images into a post.

2 Answers
2

The add_attachment action is fired when the wp_insert_attachment() function is called to add an item to the media library. Images are added to posts after going into the media library first. Even when adding via the post editor, items are added to the library with wp_insert_attachment() then to the post.

add_action( 'add_attachment', function( $post_ID ) { 
    // Do Stuff
});

This will not allow you to number items by post, only by instance in the media library. Whether that works for your purposes, I cannot answer.

https://codex.wordpress.org/Plugin_API/Action_Reference/add_attachment

Leave a Reply

Your email address will not be published. Required fields are marked *