admin管理员组文章数量:1122846
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.
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.
Share Improve this question edited Aug 9, 2017 at 6:53 Ben HartLenn 2,43518 silver badges19 bronze badges asked Aug 9, 2017 at 0:06 Abiodun AdetonaAbiodun Adetona 1713 bronze badges 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. – user3135691 Commented Aug 16, 2017 at 6:38
1 Answer
Reset to default 0If google search result brought you here see my answer to the exact same question on SO: https://stackoverflow.com/a/77546495/1568334
本文标签: pluginsHow to add custom JS to tinymce in wordpress
版权声明:本文标题:plugins - How to add custom JS to tinymce in wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293986a1929260.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论