Creating button next to “add media” that allows you to choose a single post

For WP versions before 3.5.0, use the media_buttons_context filter:

add_filter( 'media_buttons_context', function($context ) {
    global $pagenow;

    if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) ) {
        $context .= '<a href="#" class="button">Button</a>';
    }

    return $context;
} );

For 3.5.0+, use the media_buttons action:

add_action( 'media_buttons', function($editor_id){
    echo '<a href="#" class="button">Button</a>';
} );

Both will add a button beside the “Add Media” button above the post editor.

Leave a Comment