apply_filters( ‘image_send_to_editor’, string $html, int $id, string $caption, string $title, string $align, string $url, string|int[] $size, string $alt, string $rel )

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


The image HTML markup to send.
The attachment ID.
The image caption.
The image title.
The image alignment.
The image source URL.
Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
The image alternative, or alt, text.
The image rel attribute.


$html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt, $rel );


5.6.0The $rel parameter was added.

User Contributed Notes

  1. Skip to note 2 content

    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.