The get_image_send_to_editor() WordPress PHP function retrieves the image HTML to send to the editor.
Usage
get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel=false, $size='medium', $alt='');
Parameters
$id
(int) – Image attachment ID.$caption
(string) – Image caption.$title
(string) – Image title attribute.$align
(string) – Image CSS alignment property.$url
(string, optional) – Image src URL. Default is an empty string.$rel
(bool|string, optional) – Value for rel attribute or whether to add a default value. Default isfalse
.$size
(string|int, optional) – Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order). Default is'medium'
.$alt
(string, optional) – Image alt attribute. Default is an empty string.
More information
See WordPress Developer Resources: get_image_send_to_editor()
Examples
Retrieve Image HTML for an Attachment
This example retrieves the image HTML for an attachment with ID 42, a caption, a title, and aligned to the left.
$image_html = get_image_send_to_editor(42, 'This is the caption.', 'Image Title', 'left'); echo $image_html;
Retrieve Image HTML with Custom URL
This example retrieves the image HTML with a custom URL, rel attribute, and alt text.
$image_html = get_image_send_to_editor(42, 'Caption', 'Title', 'left', 'https://example.com/custom-image-url.jpg', 'lightbox', 'medium', 'Custom alt text'); echo $image_html;
Retrieve Image HTML with Different Size
This example retrieves the image HTML with a custom size (200px width and 300px height).
$image_html = get_image_send_to_editor(42, 'Caption', 'Title', 'left', '', false, array(200, 300)); echo $image_html;
Retrieve Image HTML without Caption and Title
This example retrieves the image HTML without a caption and title.
$image_html = get_image_send_to_editor(42, '', '', 'left'); echo $image_html;
Retrieve Image HTML with Center Alignment
This example retrieves the image HTML with center alignment.
$image_html = get_image_send_to_editor(42, 'Caption', 'Title', 'center'); echo $image_html;