alogo

WordPress Inline JavaScript

Inline JavaScript is possible with WordPress. But users have to give up the WordPress Visual Editor inorder to insure that the onclick= or onmouseover= and other inline JavaScript code is not stripped away by the Visual Editor. So to take advantage of the WordPress auto loading of the jQuery library, users have to give up use of the Visual Editor.

The hack workaround to enable inline JavaScript one creates a second WordPress user, say JScripter. Then with the command Users | Your Profile in which you turn off the Visual Editor for JScripter. Now you are ready to add posts using the JScripter user.

The Plus: the world of jQuery and other JavaScript libraries can be used with inline JavaScript code in WordPress Pages and Posts. The Minus: you are now using obtrusive JavaScript because it is inline. The second downside is that you get to use the WordPress Visual Editor only once until you switch over to JScripter user for adding the inline JavaScript code. After this all edits must be done in JScripter because working in a WordPress user with Visual Editor privileges will strip any inline JavaScript.

Obviously, a burning question is raised. If WordPress is going to allow inline JavaScript through this leger de main trickery of having two users – then why strip away JavaScript code in the Visual Editor at all? Finally, our next WordPress+JavaScript post will look at abandoning obtrusive inline JavaScript and replacing it with JavaScript-ed posts that can be used with the Visual Editor.

Pin It on Pinterest