3

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?

2
  • I just found this link: themergency.com/… which lets me create the button and allows me to populate the the popup box with the posts I want, now I just need to put the posts id (which I have) into a shortcode in the post. Thoughts?
    – Brucep
    Mar 8 '14 at 0:38
  • 1
    Hi Brucep, WPSE is questions / answer format , it's best to show us what you tried and ask a specific question.
    – Wyck
    Mar 8 '14 at 1:19
4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.