Sometimes when writing a block of text using the WordPress editor, you need it to look a certain way, we usually do this by adding styles to peices of text, but we don’t always want our clients to have to open up the text editor and do this manually.
In this example we will create a small filter that you can add to your
functions.php file to give the user some extra formatting options, to add a custom ‘Lead’ paragraph style.
Using the Custom TinyMCE Formatting
Here is a super quick example of the filter in action. It shows you:
- How to toggle the toolbar so that you can see the Formats menu
- How to apply the formatting using the Formats menu
- How to clear the styles
The code is really simple, just hook into
tiny_mce_before_init and add your custom style to the
style_formats array. Be sure to include a title, the type of element you want to use, and most importantly the class.
Of course, nothing will happen without a little styling. Be sure to add the styles to both your main WordPress
styles.css so your Lead shows on the Front End, and also be sure to register an editor style sheet so that the code shows in the editor (You can use
add_editor_style() to do this).
Latest posts by Matt Watson (see all)
- A Question is a Powerful Thing! - January 10, 2018
- Custom TinyMCE Editor Formatting - January 5, 2018
- Reblog: Responsive Web Design (RWD) Background Images - July 28, 2017