mce_buttons_2

Home » Hooks » mce_buttons_2

Hook Name: mce_buttons_2

In WordPress, the mce_buttons_2 hook is used to add or modify the buttons that are displayed in the second row of the TinyMCE editor toolbar. The TinyMCE editor is the visual editor used for creating and editing content in WordPress.

By using this hook, you can customize the buttons available in the second row of the editor toolbar to suit your specific needs. This allows you to provide additional functionality or remove unnecessary buttons based on your requirements.

The mce_buttons_2 hook is commonly used by developers and website owners who want to enhance the editing experience for their users. It provides a simple way to tailor the editor toolbar to match the specific features and formatting options needed for a particular website or content type.

Example Usage:

Let’s say you want to add a custom button called "Highlight" to the second row of the TinyMCE editor toolbar. This button will apply a custom CSS class to the selected text to highlight it.

You can achieve this by adding the following code to your theme’s functions.php file or a custom plugin:

function custom_mce_buttons_2($buttons) {
    $buttons[] = 'highlight';
    return $buttons;
}
add_filter('mce_buttons_2', 'custom_mce_buttons_2');

In this example, we define a function called custom_mce_buttons_2 that takes the existing $buttons array, adds the 'highlight' button to it, and returns the modified array. This function is then hooked into the mce_buttons_2 filter using the add_filter function.

Once this code is in place, the "Highlight" button will be added to the second row of the editor toolbar, giving users the ability to easily apply the custom highlight styling to selected text.

You can extend this example to perform various customizations to the TinyMCE editor toolbar by adding or removing different buttons based on your specific requirements.

Remember to always test your code and ensure it is compatible with the WordPress version you are using.

Learn More on WordPress.org

WordPress snippets using the mce_buttons_2 hook

Register an account to save your snippets or go Pro to get more features.