I use custom metaboxes quite frequently. Very often I will have a “link” field in a metabox. I’ve been using just a simple text input field, but I’m trying to figure out how to put in a button that would call the same “insert link” dialog that the WordPress content editor uses. Is that possible?
Leave a Reply
You must be logged in to post a comment.
You can invoke the link box by first enqueing the required js, and then interacting with the wp-link js files methods.
Make sure you have enqueued wp-link
1 /
wp_enqueue_script( 'wp-link' );
2 / Set up your ui. I usually use a button to invoke the link dialogue from and a textfield to handle the links URL.
3 / Invoke link dialogue
4 / Handle link saves
5 / Handle link cancels
Should about do it. I use the same approach in my metabox class and it seems to work OK. Its abit of a hack, as I’m hardcoding references to the link dialogue’s html elements. The dialogue does need an external API. Probably not all that hard to add to WP.