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.


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

Top ↑


File: wp-admin/includes/media.php. View all references

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

Top ↑


Version Description
5.6.0 The $rel parameter was added.
2.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Razon Komar Pal

    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.