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

---

# media_buttons( string $editor_id )

## In this article

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

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

Adds the media button to the editor.

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

 `$editor_id`stringrequired

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

    ```php
    function media_buttons( $editor_id = 'content' ) {
    	static $instance = 0;
    	++$instance;

    	$post = get_post();

    	if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) {
    		$post = $GLOBALS['post_ID'];
    	}

    	wp_enqueue_media( array( 'post' => $post ) );

    	$img = '<span class="wp-media-buttons-icon" aria-hidden="true"></span> ';

    	$id_attribute = 1 === $instance ? ' id="insert-media-button"' : '';

    	printf(
    		'<button type="button"%s class="button insert-media add_media" data-editor="%s" aria-haspopup="dialog" aria-controls="wp-media-modal">%s</button>',
    		$id_attribute,
    		esc_attr( $editor_id ),
    		$img . __( 'Add Media' )
    	);

    	/**
    	 * Filters the legacy (pre-3.5.0) media buttons.
    	 *
    	 * Use 'media_buttons' action instead.
    	 *
    	 * @since 2.5.0
    	 * @deprecated 3.5.0 Use 'media_buttons' action instead.
    	 *
    	 * @param string $string Media buttons context. Default empty.
    	 */
    	$legacy_filter = apply_filters_deprecated( 'media_buttons_context', array( '' ), '3.5.0', 'media_buttons' );

    	if ( $legacy_filter ) {
    		// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
    		if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) {
    			$legacy_filter .= '</a>';
    		}
    		echo $legacy_filter;
    	}
    }
    ```

[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#L641)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/media.php#L641-L683)

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

 [apply_filters_deprecated( ‘media_buttons_context’, string $string )](https://developer.wordpress.org/reference/hooks/media_buttons_context/)

Filters the legacy (pre-3.5.0) media buttons.

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

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

Fires functions attached to a deprecated filter hook.

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

Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.

  | 
| [__()](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.

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

Retrieves post data given a post ID or post object.

  |

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

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

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

## User Contributed Notes

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