I’m looking to create a button next to “add media” ( much like gravity forms “add form) that allows you to choose a custom post and then inserts that post id into a shortcode.
I’ve bene looking at hooking into tinymce for the longest time, but realized that that wasn’t the way to go (as those buttons aren’t a part of the tinymce editor).
anyone have any thoughts?
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.