You can only use Javascript in . WordPressMU driven sites like wordpress.com have set the tag filter to strip out all use of javascripts in posts, along with all CSS styles and many HTML tags for “security reasons”. You can therefore only use Javascript in the full version of WordPress, from within the posts and template files.
A lot of people want to put clocks, forms, calculations, and other widgets and gadgets driven by Javascript on their WordPress full version site. While I recommend you try to find a PHP script or Plugin replacement for the Javascript, you can still use Javascripts in WordPress templates.
If you have a lot of javascripts that you will be using consistently in your WordPress template files, then first try to put all the scripts into one group Javascript file rather than a bunch of small files. Even if you don’t use the scripts for every single page or post on your site, they can still just sit there in the single Javascript file until called.
Make sure that each script is defined by its function name such as:
function updatepage(){var m="Page updated "+document.lastMo.......}
Let’s assume that you called your group javascripts file scriptfile.js and it contains the updatepage script. When you want to use the example updatepage Javascript in a WordPress template file, add a link to the Javascript file in the header.php between the meta tags and the style sheet link in the head section. Here is an exmaple of what to add for your Javascript file link, changing the name to your script file name:
<script type="text/javascript src="/scripts/updatepage.js"></script>
Be sure that you define the type correctly, as your site will not validate without it.
In the place on your index.php, single.php, sidebar.php, or whichever template file you want to activate the Javascript, place the following code in exactly this format, changing the name to the function call of the script:
<script type="text/javascript"> <!-- updatepage(); //--></script>
Be sure and thoroughly test the generated pages with the script to make sure it works.
WordPressMU and wordpress.com users could include Javascripts inside of posts, but the developers have decided that this poses a security risk and so all javascript and many CSS and HTML tags will be automatically stripped from your post contnet. But you can use this technque within the post of the full version of WordPress.
To include a Javascript inside a post, you need to combine both the call to the script file with the call to the Javascript itself.
<script type="text/javascript" src="/scripts/updatepage.js"> </script> <script type="text/javascript"> <!-- updatepage(); //--></script>
If your Javascript doesn’t work, triple check that you haven’t made any errors during the cut and paste into a group or single file. Be sure you used a text editor and not a word processing program to create the Javascript file. Check the name of the function in the script file as well as on your site. Not all javascripts may work, and could possibly conflict with your PHP commands, but this is very rare.
If you are using the full version of WordPress and having trouble with including a lot of javascripts inside a post, try using the . This allows you to control WordPress’ automatic formatting features on a global or per post basis the ability, turning them on and off. The WordPress automatic formatting features can quickly turn a code into something readable instead of executable. To use this plugin, the entire post must be setup in HTML tags using paragraph tags and such as they will be turned off by the lack of formatting, and set the plugin options on the post that you will be using the Javascript on to have No Formating and No Character Formating. As a reminder, when using the Text Control Plugin, you must first Save and Continue Editing the post in order to see the Text Control Plugin options. This is only to be used by the brave as it is a lot of extra work.
DO NOT PASTE JAVASCRIPT CODE INTO THE COMMENTS!
They will be stripped automatically by WordPress.com. The issue to solving your problems with using Javascript inside of a post of Page in WordPress is not the Javascript code itself. Showing it to me won’t help anyone. The problem is with WordPress. You MUST follow the instructions above to the exact letter. Then it will work. Javascripts will not work in WordPress.com blogs, no matter what you do.
Site Search Tags: , , , , , , ,
.