I'm trying to Clean up pasted text in WordPress and so I've decided to followed the instructions of this tutorial.

It seems simple just to add a filter on before_wp_tiny_mce and add a setting to clean the text.

My issue is that tiny_mce_before_init is never triggered. I can see these hooks trigger : before_wp_tiny_mce, wp_tiny_mce_init, after_wp_tiny_mce but never tiny_mce_before_init.

I've looked everywhere nothing has removed the filter, no extension to replace tinymce.

If anyone has an idea ?

Edit, here is the code (i've tried to put it in the function.php of my child themes where others hooks are and working) :


 * Customize TinyMCE's configuration
 * @param   array
 * @return  array
function configure_tinymce($in) {
  $in['paste_preprocess'] = "function(plugin, args){
    // Strip all HTML tags except those we have whitelisted
    var whitelist = 'p,span,b,strong,i,em,h3,h4,h5,h6,ul,li,ol';
    var stripped = jQuery('<div>' + args.content + '</div>');
    var els = stripped.find('*').not(whitelist);
    for (var i = els.length - 1; i >= 0; i--) {
      var e = els[i];
    // Strip all class and id attributes
    // Return the clean HTML
    args.content = stripped.html();
  return $in;
  • 2
    There's no code in your question, can you edit your question to add it? Also where is the code? The location and when it loads is important – Tom J Nowell Jan 26 '18 at 15:59

Looking at the contents of class-wp-editor.php, it looks like tiny_mce_before only triggers if you are not using the Teeny version of the editor:

 * For people who really REALLY know what they're doing with TinyMCE
 * You can modify $mceInit to add, remove, change elements of the config
 * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
 * and "extended_valid_elements" can be done through this filter. Best
 * is to use the default cleanup by not specifying valid_elements,
 * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
if ( $set['teeny'] ) {

     * Filters the teenyMCE config before init.
     * @since 2.7.0
     * @param array  $mceInit   An array with teenyMCE config.
     * @param string $editor_id Unique editor identifier, e.g. 'content'.
    $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
} else {

     * Filters the TinyMCE config before init.
     * @since 2.5.0
     * @param array  $mceInit   An array with TinyMCE config.
     * @param string $editor_id Unique editor identifier, e.g. 'content'.
    $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );

If the config can work for both Tiny and Teeny, you could hook on both filters to modify the configuration.

  • thanks ! i'll try it and let you know, i did notice the teeny/tiny settings but i was very far to think that changes hooks logical too ... – Aliiiiiiii Jan 28 '18 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.