I find the solution using this How to change the markup WordPress inserts for post images
My final code is:
add_filter( 'image_send_to_editor', 'add_custom_data_attribute_send_to_editor', 10, 8 );
function add_custom_data_attribute_send_to_editor( $html, $id, $caption, $title, $align, $url, $size, $alt ){
if( $id > 0 ){
$post = get_post( $id );
$html = str_replace( "<img src", "<h2>$alt</h2><img src", $html );
}
return $html;
}
Related Posts:
- Restricting users to view only media library items they have uploaded?
- Prevent WordPress from generating medium_large 768px size of image uploads?
- Set default image link target in Gutenberg image block
- Using Images in WordPress – Best Practices
- Media Upload Folder – how to manage
- How to set the default embed image size
- Filter Media Library by author or post_parent
- Use Media Library to manage galleries like Nextgen (with folders, albums, collections, tags, categories, terms…)
- How do i upload an image and return the image id?
- Insert Images at Master Uniform Height
- Alter media caption/description conflict in WordPress?
- Upload images using FTP and show them in media
- Media sizes aren’t being created – server config?
- Add visual editor to Media Edit Screen
- custom image size with New Media Manager in wordpress 3.5
- How to add a media with PHP
- How to make programmatic image upload generate thumbnail and sizes?
- Can’t access ‘Store uploads in this folder’
- How to add qtranslate multi language support for media?
- Best way to strip character entities (%20 etc)
- What’s the best “insert all images” plugin?
- 3.5 media.editor: what is the event listener for choosing an image?
- Getting alt text of featured image
- Get image alt attribute just by image URL
- Is there a way to get attachment data?
- Rename media files generated during upload
- Thumbnails are bigger in size than the original image
- Link to full size image or attachment page in photo theme
- HTTP Error when uploading files above 7mb unless using GD Image Editor
- How Do I Delete All The Images from WordPress
- Change WordPress Media Manager
- Bulk edit of EXIF data for jpeg images uploaded in the media library?
- Upload media files to Amazon S3
- image in my post disappeared after I upload website to remote server
- Handling image uploads without thickbox
- Pull images from the gallery
- WordPress automatically downscaled images larger that original
- How to change image atributes right before an image to be saved?
- Is it possible to change ‘Link to’ in all images in all articles?
- Searching for any images in media library displays “no media found”
- Ho to add “Create Slider” option to default “Add Media” popup?
- How to filter the image embed code based on link type
- Why it doesn’t show media urls on rest Api? (WordPress)
- How to get file URL from media library
- Edit image results in copies of file being created
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Change wp-content/uploads to uploads/%postname%/%image%
- Blank upload.php page
- Post and featured image have the same name, why is the attachment (image) is showing and not the post?
- Export xml use/import images from theme directory
- Upload box media size not working
- Is it possible to change image size used for preview thumnail in Add Media popup
- Why does WP allow to view and media item as a page
- Function to remove all classes on images inserted into posts?
- Get images attached to a specific page
- Why WordPress suddenly changed sizes of thumbnails?
- Auto delete pictures in media library by age
- Is it possible to enable the ‘Link To’ field under ‘Attachment Display Settings’ for a Featured Image?
- WordPress Attachments with old images
- Disable image rename on upload
- Set Featured Image not opening – Stuck at loading
- How to remove “Image Information” and “post date/author” from a media page?
- How can i identify media uploaded to my website that is not being used anywhere anymore?
- image URL changed in wordpress
- Can’t seem to see images on my machine but can on the server
- Serving Images from subdomain in wordpress
- User uploads image as “Featured Image” but WordPress resizes it?
- Profile image does not upload
- WordPress append -1 to the image name
- Allow a specific user role I have created to only upload one image to his media library
- cant upload media/pictures to my wordpress site, cant upload anything to my database
- How to display the Media Library Items Upload date
- Upload error on localhost (at minimum, not yet tested online)
- Built-in image lazy loading: Does it come with a polyfill for older browsers?
- Images not loading on webpage, and links to other media give 404 Not Found
- unsharp thumbnails after uploading image
- Updated wordpress missing image upload area
- Post-processing of the image failed
- Generate links on all images in posts – is there a hook?
- Use wget to find used images
- Modify media file markup output
- Unable to delete images in Media Library
- How to regularly backup and update WordPress website with lot of images?
- wordpress images not showing properly
- Edit image itself
- How do I display image files as links?
- page displaying media caption shortcodes
- How do I embed youtube video via url in frontend posting
- Missing Images in Uploads Directory (Server Only)
- Set padding for all content except images and few more elements
- Broken Media Library
- Change image link in excerpt to point to post
- Aviary + WordPress Media
- Media Library is not loading on grid view in admin panel
- WP is showing wrong image dimensions
- Blurry Images WordPress 5.8.1
- Why some images are not allowed to be edited only for thumbnails?
- How to import external media items into wordpress media library (without using storage)
- Delete all thumbnails & regenerate them?
- Uploading media to wordpress API with C# HttpClient