I'm familiar with creating self-closing shortcodes like:
// shortcode
function wpse_shortcode_example( $wpse_atts ) {
// Attributes
$wpse_atts = shortcode_atts(
array(
'foo' => 'bar',
'width' => '100%',
'height' => 'auto',
),
$wpse_atts,
'wpse'
);
// Return
return '<embed
src="' . $wpse_atts['src'] . '"
width="' . $wpse_atts['width'] . '"
height="' . $wpse_atts['height'] . '";
}
add_shortcode( 'wpse', 'wpse_shortcode_example' );
but I would like to start adding these to the TinyMCE. I've done several searches but all of the search results are either dated or use an approach that is no longer recommended:
- How to add a shortcode button to the TinyMCE editor?: excellent starting point but the question was created in 2012.
- WordPress Shortcodes: A Complete Guide: good article but from 2012 and it uses
query_posts()
but could be tweaked - Guide to Creating Your Own WordPress Editor Buttons: is a nice article but still from awhile ago, 2013, but it doesn't cover the basics or foundation to use TinyMCE.
I know Developer is still in it's early stages but the Plugin Handbook only briefly talks about TinyMCE Enhanced Shortcodes and Shortcode API and add_shortcode()
don't mention TinyMCE.
So this leads me to my question. What is the basic procedure for turning a self-closing shortcode into a clickable button in the TinyMCE editor?