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.

Parameters

$htmlstring
The image HTML markup to send.
$idint
The attachment ID.
$captionstring
The image caption.
$titlestring
The image title.
$alignstring
The image alignment.
$urlstring
The image source URL.
$sizestring|int[]
Requested image size. Can be any registered image size name, or an array of width and height values in pixels (in that order).
$altstring
The image alternative, or alt, text.
$relstring
The image rel attribute.

Source

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

Changelog

VersionDescription
5.6.0The $rel parameter was added.
2.5.0Introduced.

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.