get_image_send_to_editor

Retrieves the image HTML to send to the editor.

Description

(string) get_image_send_to_editor( (int) $id, (string) $caption, (string) $title, (string) $align, (string) $url = '', (constant) $rel = false, (string) $size = 'medium', (string) $alt = '' ); 

Returns (string)

The HTML output to insert into the editor.

Parameters (8)

0. $id (int)
Image attachment id.
1. $caption (string)
Image caption.
2. $title (string)
Image title attribute.
3. $align (string)
Image CSS alignment property.
4. $url — Optional. (string) => ''
Image src URL. Default empty.
5. $rel — Optional. (constant) => false
Value for rel attribute or whether to add a default value. Default false.
6. $size — Optional. (string) => 'medium'
Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default medium..
7. $alt — Optional. (string) => ''
Image alt attribute. Default empty.

Usage

  1. if ( !function_exists( 'get_image_send_to_editor' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // Image attachment id. 
  5. $id = -1; 
  6.  
  7. // Image caption. 
  8. $caption = ''; 
  9.  
  10. // Image title attribute. 
  11. $title = ''; 
  12.  
  13. // Image CSS alignment property. 
  14. $align = ''; 
  15.  
  16. // Optional. Image src URL. Default empty. 
  17. $url = ''; 
  18.  
  19. // Optional. Value for rel attribute or whether to add a default value. Default false. 
  20. $rel = false; 
  21.  
  22. // Optional. Image size. Accepts any valid image size, or an array of width 
  23. // and height values in pixels (in that order). Default 'medium'. 
  24. $size = 'medium'; 
  25.  
  26. // Optional. Image alt attribute. Default empty. 
  27. $alt = ''; 
  28.  
  29. // NOTICE! Understand what this does before running. 
  30. $result = get_image_send_to_editor($id, $caption, $title, $align, $url, $rel, $size, $alt); 
  31.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) { 
  2.  
  3. $html = get_image_tag( $id, $alt, '', $align, $size ); 
  4.  
  5. if ( $rel ) { 
  6. if ( is_string( $rel ) ) { 
  7. $rel = ' rel="' . esc_attr( $rel ) . '"'; 
  8. } else { 
  9. $rel = ' rel="attachment wp-att-' . intval( $id ) . '"'; 
  10. } else { 
  11. $rel = ''; 
  12.  
  13. if ( $url ) 
  14. $html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>'; 
  15.  
  16. /** 
  17. * Filters the image HTML markup to send to the editor when inserting an image. 
  18. * @since 2.5.0 
  19. * @param string $html The image HTML markup to send. 
  20. * @param int $id The attachment id. 
  21. * @param string $caption The image caption. 
  22. * @param string $title The image title. 
  23. * @param string $align The image alignment. 
  24. * @param string $url The image source URL. 
  25. * @param string|array $size Size of image. Image size or array of width and height values 
  26. * (in that order). Default 'medium'. 
  27. * @param string $alt The image alternative, or alt, text. 
  28. */ 
  29. $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt ); 
  30.  
  31. return $html;