/*************** ajoute TinyMCE bouton ********************/ // Filter Functions with Hooks function custom_mce_button() { // Check if user have permission if ( !current_user_can( 'edit_posts' ) || !current_user_can( 'edit_pages' ) ) { return; } // Check if WYSIWYG is enabled if ( 'true' == get_user_option( 'rich_editing' ) ) { add_filter( 'mce_external_plugins', 'custom_tinymce_plugin' ); add_filter( 'mce_buttons', 'register_mce_button' ); } } add_action('admin_head', 'custom_mce_button'); // Function for new button function custom_tinymce_plugin( $plugin_array ) { $plugin_array['custom_mce_button1'] = get_stylesheet_directory_uri() .'/tinymce_bouton1.js'; $plugin_array['custom_mce_button2'] = get_stylesheet_directory_uri() .'/tinymce_bouton2.js'; return $plugin_array; } // Register new button in the editor function register_mce_button( $buttons ) { array_push( $buttons, 'custom_mce_button1' ); array_push( $buttons, 'custom_mce_button2' ); return $buttons; } /************** Fin ajoute TinyMCE button *****************/
js dans child theme – get_stylesheet_directory_uri() = child theme
(function() { tinymce.PluginManager.add('custom_mce_button1', function(editor, url) { editor.addButton('custom_mce_button1', { text: 'Showhide EN', icon: false, onclick: function() { editor.insertContent('[mon_shortcode mon_attr="toto" autre_attr="tata"][/mon_shortcode '); } }); }); })();
0 commentaires