Title: edit_form_image_editor
Published: April 25, 2014
Last modified: February 24, 2026

---

# edit_form_image_editor( WP_Post $post )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#wp--skip-link--target)

Displays the image and editor in the post editor

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#parameters)󠁿

 `$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)required

A post object.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#source)󠁿

    ```php
    function edit_form_image_editor( $post ) {
    	$open = isset( $_GET['image-editor'] );

    	if ( $open ) {
    		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    	}

    	$thumb_url     = false;
    	$attachment_id = (int) $post->ID;

    	if ( $attachment_id ) {
    		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
    	}

    	$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );

    	$att_url = wp_get_attachment_url( $post->ID );
    	?>
    	<div class="wp_attachment_holder wp-clearfix">
    	<?php

    	if ( wp_attachment_is_image( $post->ID ) ) :
    		$image_edit_button = '';
    		if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
    			$nonce             = wp_create_nonce( "image_editor-$post->ID" );
    			$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
    		}

    		$open_style     = '';
    		$not_open_style = '';

    		if ( $open ) {
    			$open_style = ' style="display:none"';
    		} else {
    			$not_open_style = ' style="display:none"';
    		}

    		?>
    		<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>

    		<div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
    			<p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p>
    			<p><?php echo $image_edit_button; ?></p>
    		</div>
    		<div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
    		<?php

    		if ( $open ) {
    			wp_image_editor( $attachment_id );
    		}

    		?>
    		</div>
    		<?php
    	elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) :

    		wp_maybe_generate_attachment_metadata( $post );

    		echo wp_audio_shortcode( array( 'src' => $att_url ) );

    	elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) :

    		wp_maybe_generate_attachment_metadata( $post );

    		$meta = wp_get_attachment_metadata( $attachment_id );
    		$w    = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0;
    		$h    = ! empty( $meta['height'] ) ? $meta['height'] : 0;

    		if ( $h && $w < $meta['width'] ) {
    			$h = round( ( $meta['height'] * $w ) / $meta['width'] );
    		}

    		$attr = array( 'src' => $att_url );

    		if ( ! empty( $w ) && ! empty( $h ) ) {
    			$attr['width']  = $w;
    			$attr['height'] = $h;
    		}

    		$thumb_id = get_post_thumbnail_id( $attachment_id );

    		if ( ! empty( $thumb_id ) ) {
    			$attr['poster'] = wp_get_attachment_url( $thumb_id );
    		}

    		echo wp_video_shortcode( $attr );

    	elseif ( isset( $thumb_url[0] ) ) :
    		?>
    		<div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
    			<p id="thumbnail-head-<?php echo $attachment_id; ?>">
    				<img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" />
    			</p>
    		</div>
    		<?php

    	else :

    		/**
    		 * Fires when an attachment type can't be rendered in the edit form.
    		 *
    		 * @since 4.6.0
    		 *
    		 * @param WP_Post $post A post object.
    		 */
    		do_action( 'wp_edit_form_attachment_display', $post );

    	endif;

    	?>
    	</div>
    	<div class="wp_attachment_details edit-form-section">
    	<?php if ( str_starts_with( $post->post_mime_type, 'image' ) ) : ?>
    		<p class="attachment-alt-text">
    			<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
    			<textarea class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" aria-describedby="alt-text-description"><?php echo esc_attr( $alt_text ); ?></textarea>
    		</p>
    		<p class="attachment-alt-text-description" id="alt-text-description">
    		<?php

    		printf(
    			/* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */
    			__( '<a href="%1$s" %2$s>Learn how to describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
    			/* translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. */
    			esc_url( __( 'https://www.w3.org/WAI/tutorials/images/decision-tree/' ) ),
    			'target="_blank"',
    			sprintf(
    				'<span class="screen-reader-text"> %s</span>',
    				/* translators: Hidden accessibility text. */
    				__( '(opens in a new tab)' )
    			)
    		);

    		?>
    		</p>
    	<?php endif; ?>

    		<p>
    			<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
    			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
    		</p>

    	<?php

    	$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
    	$editor_args        = array(
    		'textarea_name' => 'content',
    		'textarea_rows' => 5,
    		'media_buttons' => false,
    		/**
    		 * Filters the TinyMCE argument for the media description field on the attachment details screen.
    		 *
    		 * @since 6.6.0
    		 *
    		 * @param bool $tinymce Whether to activate TinyMCE in media description field. Default false.
    		 */
    		'tinymce'       => apply_filters( 'activate_tinymce_for_media_description', false ),
    		'quicktags'     => $quicktags_settings,
    	);

    	?>

    	<label for="attachment_content" class="attachment-content-description"><strong><?php _e( 'Description' ); ?></strong>
    	<?php

    	if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
    		echo ': ' . __( 'Displayed on attachment pages.' );
    	}

    	?>
    	</label>
    	<?php wp_editor( format_to_edit( $post->post_content ), 'attachment_content', $editor_args ); ?>

    	</div>
    	<?php

    	$extras = get_compat_media_markup( $post->ID );
    	echo $extras['item'];
    	echo '<input type="hidden" id="image-edit-context" value="edit-attachment" />' . "\n";
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/media.php#L3119)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/media.php#L3119-L3298)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#hooks)󠁿

 [apply_filters( ‘activate_tinymce_for_media_description’, bool $tinymce )](https://developer.wordpress.org/reference/hooks/activate_tinymce_for_media_description/)

Filters the TinyMCE argument for the media description field on the attachment details
screen.

 [do_action( ‘wp_edit_form_attachment_display’, WP_Post $post )](https://developer.wordpress.org/reference/hooks/wp_edit_form_attachment_display/)

Fires when an attachment type can’t be rendered in the edit form.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_attachment_is()](https://developer.wordpress.org/reference/functions/wp_attachment_is/)`wp-includes/post.php` |

Verifies an attachment is of a given type.

  | 
| [wp_image_editor()](https://developer.wordpress.org/reference/functions/wp_image_editor/)`wp-admin/includes/image-edit.php` |

Loads the WP image-editing interface.

  | 
| [get_compat_media_markup()](https://developer.wordpress.org/reference/functions/get_compat_media_markup/)`wp-admin/includes/media.php` |  | 
| [esc_attr__()](https://developer.wordpress.org/reference/functions/esc_attr__/)`wp-includes/l10n.php` |

Retrieves the translation of $text and escapes it for safe use in an attribute.

  | 
| [format_to_edit()](https://developer.wordpress.org/reference/functions/format_to_edit/)`wp-includes/formatting.php` |

Acts on text which is about to be edited.

  | 
| [wp_editor()](https://developer.wordpress.org/reference/functions/wp_editor/)`wp-includes/general-template.php` |

Renders an editor.

  | 
| [set_url_scheme()](https://developer.wordpress.org/reference/functions/set_url_scheme/)`wp-includes/link-template.php` |

Sets the scheme for a URL.

  | 
| [get_post_thumbnail_id()](https://developer.wordpress.org/reference/functions/get_post_thumbnail_id/)`wp-includes/post-thumbnail-template.php` |

Retrieves the post thumbnail ID.

  | 
| [wp_maybe_generate_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_maybe_generate_attachment_metadata/)`wp-includes/media.php` |

Maybe attempts to generate attachment metadata, if missing.

  | 
| [wp_image_editor_supports()](https://developer.wordpress.org/reference/functions/wp_image_editor_supports/)`wp-includes/media.php` |

Tests whether there is an editor that supports a given mime type or methods.

  | 
| [wp_video_shortcode()](https://developer.wordpress.org/reference/functions/wp_video_shortcode/)`wp-includes/media.php` |

Builds the Video shortcode output.

  | 
| [wp_audio_shortcode()](https://developer.wordpress.org/reference/functions/wp_audio_shortcode/)`wp-includes/media.php` |

Builds the Audio shortcode output.

  | 
| [wp_get_attachment_image_src()](https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/)`wp-includes/media.php` |

Retrieves an image to represent an attachment.

  | 
| [wp_attachment_is_image()](https://developer.wordpress.org/reference/functions/wp_attachment_is_image/)`wp-includes/post.php` |

Determines whether an attachment is an image.

  | 
| [wp_get_attachment_url()](https://developer.wordpress.org/reference/functions/wp_get_attachment_url/)`wp-includes/post.php` |

Retrieves the URL for an attachment.

  | 
| [wp_get_attachment_metadata()](https://developer.wordpress.org/reference/functions/wp_get_attachment_metadata/)`wp-includes/post.php` |

Retrieves attachment metadata for attachment ID.

  | 
| [_e()](https://developer.wordpress.org/reference/functions/_e/)`wp-includes/l10n.php` |

Displays translated text.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [esc_attr()](https://developer.wordpress.org/reference/functions/esc_attr/)`wp-includes/formatting.php` |

Escaping for HTML attributes.

  | 
| [esc_url()](https://developer.wordpress.org/reference/functions/esc_url/)`wp-includes/formatting.php` |

Checks and cleans a URL.

  | 
| [wp_create_nonce()](https://developer.wordpress.org/reference/functions/wp_create_nonce/)`wp-includes/pluggable.php` |

Creates a cryptographic token tied to a specific action, user, user session, and window of time.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_post_meta()](https://developer.wordpress.org/reference/functions/get_post_meta/)`wp-includes/post.php` |

Retrieves a post meta field for the given post ID.

  |

[Show 19 more](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/edit_form_image_editor/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.5.0](https://developer.wordpress.org/reference/since/3.5.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fedit_form_image_editor%2F)
before being able to contribute a note or feedback.