apply_filters( 'image_send_to_editor', string $html, int $id, string $caption, string $title, string $align, string $url, string|array $size, string $alt )

Filters the image HTML markup to send to the editor when inserting an image.

Parameters Parameters


(string) The image HTML markup to send.


(int) The attachment ID.


(string) The image caption.


(string) The image title.


(string) The image alignment.


(string) The image source URL.


(string|array) Size of image. Image size or array of width and height values (in that order). Default 'medium'.


(string) The image alternative, or alt, text.

Top ↑

Source Source

File: wp-admin/includes/media.php

View on Trac

Top ↑

Changelog Changelog

Version Description
2.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Razon

    Add custom field to media attachment image attribute in post editor

     * Add the data-media-description and data-media-full attributes to inserted image tag. 
    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 );
    		$media_data = array(
    			$post->ID, // media id[0]
    			$post->post_content, // media description
    			$post->post_excerpt // media caption
    		$img_size = wp_get_attachment_image_src($id, 'full'); // get media full size url
    		$data  = sprintf( ' data-media-description="%s"', esc_attr( $media_data[1] ) ); // set data-media-description
    		$data .= sprintf( ' data-media-url="%s" ', esc_url( $img_size[0] ) ); // set data-media-url
    		$html = str_replace( "<img src", "<img{$data}src", $html ); // replace and add custom attributes
    	return $html;

You must log in before being able to contribute a note or feedback.