image_media_send_to_editor() WordPress Function

The image_media_send_to_editor() function allows you to send an image to the editor in the WordPress media library. This function is useful for sending images that you have uploaded to your WordPress site to the editor for use in your posts and pages.

image_media_send_to_editor( string $html, int $attachment_id, array $attachment ) #

Retrieves the media element HTML to send to the editor.


Parameters

$html

(string)(Required)

$attachment_id

(int)(Required)

$attachment

(array)(Required)


Top ↑

Return

(string)


Top ↑

Source

File: wp-admin/includes/media.php

function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
	$post = get_post( $attachment_id );

	if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
		$url   = $attachment['url'];
		$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none';
		$size  = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
		$alt   = ! empty( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
		$rel   = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $attachment_id ) === $url );

		return get_image_send_to_editor( $attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt );
	}

	return $html;
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More