Does WordPress Strip JavaScript?

WordPress is a tool to power your website or blog that is available as both a script you can install to your server and a hosted blog solution.You should consider the self-hosted version of WordPress if you wish to use JavaScript on your website. Blogs registered and hosted on WordPress block JavaScript, except from a few trusted sites, to avoid malicious codes.

  1. JavaScript in Posts

    • You can display JavaScript in your posts and pages by pasting or typing the code into the entry editor. However, you must use the HTML editor and not the visual editor. If you switch to the visual editor, you will not be able to view your JavaScript and WordPress will remove it from the post. Thus, you should use the "Preview" feature to view your post in your browser, rather than the visual editor to preview your JavaScript.

    Javascript on Website

    • If you use WordPress on a self-hosted website and are able to edit any of the template files, you can insert JavaScript as you see fit. JavaScript that is used to add tracking codes and enable functions generally belongs in the head of your document; although, some code sources may suggest you place it before the closing "</body>" tag to help your website load more quickly. You can also choose to show widgets and other content by creating a text widget from within your dashboard and inserting JavaScript there.

    Considerations

    • The WordPress editor will attempt to condense code, so if your JavaScript spans several lines, it may not work correctly because the line breaks have been removed. Furthermore, if you attempt to use JavaScript in the visual editor, WordPress may add line breaks or paragraphs to your code, rendering it useless. You can install plugins to your self-hosted WordPress blog that allow you to remove the default formatting so codes will work on your posts and pages.

    Warning

    • WordPress will block any JavaScript that you attempt to install in posts or widgets on hosted blog. Thus, you cannot display widgets or using tracking codes that rely on JavaScript. According to the creators, this ban is because some JavaScript can be malicious and "JavaScript has taken sites such as MySpace.com and LiveJournal offline in the past." However, WordPress will allow JavaScript from trusted websites such as YouTube and will convert the code into a WordPress shortcode in posts on your hosted blog.

Related Searches:

References

Comments

Related Ads

Featured