Using WordPress ‘media_buttons’ PHP action

The media_buttons WordPress PHP action allows you to add custom media buttons right after the default media button(s) in the editor.

Usage

add_action('media_buttons', 'your_custom_function_name');
function your_custom_function_name() {
    // your custom code here
}

Parameters

  • No parameters for this action.

More information

See WordPress Developer Resources: media_buttons

Examples

Add a custom button to the media buttons

This example shows how to add a custom button next to the default “Add Media” button.

add_action('media_buttons', 'my_custom_media_button');
function my_custom_media_button() {
    echo '<a href="#" class="button" id="my-custom-button">My Custom Button</a>';
}

Add an additional image uploader

This example adds an additional image uploader button to the media buttons section.

add_action('media_buttons', 'extra_image_uploader');
function extra_image_uploader() {
    echo '<a href="#" class="button insert-image">Insert Image</a>';
}

Add a custom video embed button

This example demonstrates adding a custom video embed button next to the default media button(s).

add_action('media_buttons', 'add_video_embed_button');
function add_video_embed_button() {
    echo '<a href="#" class="button" id="video-embed-button">Embed Video</a>';
}

Add a shortcode inserter button

This example shows how to add a button that inserts a shortcode in the editor.

add_action('media_buttons', 'shortcode_inserter_button');
function shortcode_inserter_button() {
    echo '<a href="#" class="button" id="insert-shortcode-button">Insert Shortcode</a>';
}

Add a button with an icon

This example demonstrates adding a custom button with an icon next to the default media button(s).

add_action('media_buttons', 'add_icon_button');
function add_icon_button() {
    echo '<a href="#" class="button" id="icon-button"><span class="dashicons dashicons-format-gallery"></span> Icon Button</a>';
}