I have a plugin that uses the wp_editor()
function to load an instance of the TinyMCE editor.
However, the editor is affected by custom styling to make it look similar to the theme through the add_editor_style()
function. While this may be great in giving the user an idea of how the content may look on the front-end, I do not want this as the content will only ever be displayed on the back-end.
Is there any way to load an instance of the WordPress editor without it being affected by custom styling?
While @s_ha_dumâs solution works fine on a custom plugin page, it will fail if you use TinyMCE on a post editor page after the first editor instance has been called, because it would either affect all editors or at least the editors later on the same page. TinyMCE parses custom styles into its settings during the first run only.
How to remove the custom styles for one editor only?
Letâs say we replace the excerpt box with a rich editor in a class with static methods only:
To remove the custom styles for just one special editor ID, we can filter
teeny_mce_before_init
if we have set'teeny' => TRUE
andtiny_mce_before_init
otherwise.See
_WP_Editors::editor_settings()
:In this example it is
teeny_mce_before_init
, and we need a simple helper method:Now we register that as callback before we call
wp_editor()
:Thatâs all. Only editors with our ID will get no custom styles now. No untestable side effect, our code stays compatible with other code in all situations.
I believe you want
remove_editor_styles
. Looks like it removes the theme support for editor styles.If you run that on your plugin’s backend page before the editor boots, it should solve the problem. There might be a parameter you can pass to the editor functions, or a hook, but removing the editor style support for the effected page was the first thing that came to my mind.
Untested and I haven’t done much with editor styles but it seems pretty straightforward.