3

So I want to enhance the functionality of the TinyMCE editor in WordPress by adding custom JS script and CSS to it.

I was able to add custom CSS to it by using this method:

function plugin_mce_css($stylesheet) {    
    $stylesheet .= ','; 

    $stylesheet .= plugins_url ('editor.css', __FILE__); 

    return $stylesheet;
}
add_action( 'mce_css', 'plugin_mce_css' );

Using that, I was able to add some styling to the wp-editor css class but when it got to adding custom Js script I wasn't able to do any DOM manipulation of Wp-editor after adding JS script with this method:

function custom_script() { 
    printf( '<script type="text/javascript" src="%s"></script>',  plugins_url('editor.js', __FILE__) ); 
}
add_action( 'after_wp_tiny_mce', 'custom_script' );

What am I getting wrong when adding the JS? I need help.

1
  • I'm not very deep into this but as far as I know, you should never use printf to print out scripts in WordPress. In case you want to use inline script tags, you should go for the admin_head hook. Maybe worth a try. Aug 16, 2017 at 6:38

1 Answer 1

0

If google search result brought you here see my answer to the exact same question on SO: https://stackoverflow.com/a/77546495/1568334

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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