I have successfully written a TinyMCE plugin for a WordPress site that inserts a script tag into the html of a new post or page. However, since the script tag contains no text, in the “visual” pane nothing shows up.
There must be a way to provide something to show in the visual pane while still only having a script tag in the “text” pane no?
My code:
jQuery(document).ready(function($) {
tinymce.PluginManager.add('myplugin', function(editor, url) {
editor.addButton('civicsciencejspoll', {
text: 'CivicScience JSPoll',
icon: false,
onclick: function() {
var html = "<script src="mydomain.com/js/file.js"></script>";
editor.insertContent(html);
}
}
});
});
});
I ended up using WordPress’s ShortCode API to achieve my desired effect:
https://codex.wordpress.org/Shortcode_API