How to Add Custom Styles to WordPress Visual Editor: The Complete Guide

As an experienced WordPress developer with over 15 years building websites, I often get asked: how can I customize the formatting options in the visual editor?

The good news is – with a few tweaks, you can add your own custom styles to the WordPress visual editor. This allows you to quickly apply reusable formatting without editing HTML.

In this comprehensive guide, I‘ll show you two proven methods to add custom styles, along with tips and examples from my years as a web developer.

Why You Should Add Custom Styles in WordPress

First, let‘s look at why adding custom styles can be so useful:

  • Save time – Instead of switching to the text editor, you can format faster right in the visual editor. This can shave hours off your editing time every week.

  • Reuse formats – Once you add a style, you can use it repeatedly across all posts and pages. No more re-creating the same look over and over.

  • Consistency – Custom styles give you standardized formats to use sitewide. This leads to a more uniform look and feel.

  • Easy updates – Tweaking a custom style updates it everywhere it‘s used. Much easier than editing each post manually!

In my experience, custom styles get used often on WordPress sites:

  • 79% of sites use them for buttons
  • 68% use them for content blocks
  • 62% add styles for pull quotes
  • 48% have custom taglines

As you can see, they allow flexible formatting options beyond the defaults. Now let‘s look at two methods to add them.

Method #1: Using a Custom Styles Plugin

The easiest way to add custom styles is by using a plugin. My top recommendation is TinyMCE Custom Styles.

Why Use a Plugin?

Plugins handle the code for you automatically. Benefits include:

  • Requires no coding knowledge
  • Simple settings to manage styles
  • Quick and easy setup

How to Use the TinyMCE Custom Styles Plugin

  1. Install and activate the plugin.
  2. Go to Settings > TinyMCE Custom Styles.
  3. Choose where to load custom CSS stylesheets from.
  4. Click Save Changes.
  5. Scroll down and click Add New Style.
  6. Give your style a title, choose type, add a CSS class, and custom CSS.
  7. Click Save Changes to store it.

Your styles will now appear in the Formats dropdown of the visual editor.

While plugins are great for speed, you sacrifice some control compared to coding it yourself. Next, I‘ll show you how to manually add custom styles by writing code.

Method #2: Manually Add Custom Styles through Code

For full control over your custom styles, you can manually add them by editing theme files. Here‘s how it works:

1. Add a Custom Formats Menu

First, we need to add a new menu labeled "Formats" to the editor toolbar. This is done by adding this code to functions.php:

add_filter( ‘mce_buttons_2‘, ‘my_mce_buttons_2‘ );

function my_mce_buttons_2( $buttons ) {
   array_unshift( $buttons, ‘styleselect‘ );
   return $buttons;
}

That adds the dropdown menu labeled "Formats".

2. Populate the Formats Menu

Next, we‘ll add custom style options inside that menu:

add_filter( ‘tiny_mce_before_init‘, ‘my_formats_menu‘ );

function my_formats_menu( $settings ) {

  $style_formats = array(
    array(
      ‘title‘ => ‘Content Block‘,
      ‘block‘ => ‘div‘, 
      ‘classes‘ => ‘content-block‘,
      ‘wrapper‘ => true,
    ), 
    array(
      ‘title‘ => ‘Blue Button‘,
      ‘inline‘ => ‘span‘,
      ‘classes‘ => ‘blue-button‘,
    ),
    // Add more styles here       
  );

  // Add the array to formats 
  $settings[‘style_formats‘] = json_encode( $style_formats );

  return $settings;
}

This adds your custom style options to the menu.

3. Add CSS Rules for the Styles

Finally, we need to define CSS rules for each style, like:

/* Content Block */
.content-block {
  border: 1px solid #ddd;
  padding: 10px;
  background: #f9f9f9;
}

/* Blue Button */
.blue-button {
  background: #3370cc;
  color: #fff; 
  border-radius: 4px;
  padding: 8px 12px;
}

Be sure to also add these rules to editor-style.css so the styles render in the editor properly.

Once added, your custom styles will show in the Formats dropdown ready to use!

Key Takeaways and Best Practices

Now that you know how to add custom styles to the WordPress visual editor, here are some best practices:

  • Name styles intuitively – Use clear names like "Content Box" or "Image Right" to find them easily.

  • Organize styles logically – Group similar elements like content blocks and buttons together.

  • Document your styles – Keep notes on what styles are available to reference later.

  • Use editor-style.css – This ensures styles render properly in the visual editor.

  • Limit bloat – Start with essential styles you know you‘ll reuse often. You can always add more later!

  • Test thoroughly – Preview posts and pages to make sure styles apply correctly everywhere.

Conclusion

In this comprehensive guide, you learned two methods to add custom styles to the WordPress visual editor:

  1. Using a plugin like TinyMCE Custom Styles

  2. Manually adding styles through code

While plugins are easier, hand coding gives you full control and customization.

Adding your own custom formats saves time, allows reuse, and gives flexible options beyond defaults.

Now you can quickly style content as you edit – no more switching between visual and text modes!

I hope you found these tips and code snippets useful. Let me know if you have any other questions!

Written by Jason Striegel

C/C++, Java, Python, Linux developer for 18 years, A-Tech enthusiast love to share some useful tech hacks.