I have developed a JavaScript widget which works fine when I embed it in any of my html pages. The code is something like this

<script type="text/javascript" charset="utf-8">
  var asset_host = 'http://domain.com';
  var url = unescape("%3Cscript src='" + asset_host + "/javascripts/widget.js' type='text/javascript'%3E%3C/script%3E");

<script type="text/javascript" charset="utf-8">
  var widget_options = {};
  widget_options.iframe_base_url =  asset_host + '/widget/questions/10';
  var feedback_widget = new ShowWidget.widget(widget_options);

However when I embed this code in wordpress then "style" tag is being stripped off ( probably for security reasons).

How should I go about generating the widget code for wordpress so that users have least amount of inconvenience.

  • @user880 I edited the title because as we discussed this issue only applies to WordPress.com hosted sites.
    – Chris_O
    Sep 17, 2010 at 17:19

2 Answers 2


WordPress.com does not allow you to post javascript.

From WordPress.com Support:

Users are not allowed to post JavaScript on WordPress.com blogs. JavaScript can be used for malicious purposes. As an example, JavaScript has taken down sites such as MySpace.com and LiveJournal offline in the past. The security of all the blogs is a top priority and until we can guarantee scripting languages will not be harmful they will not be permitted.

JavaScript from trusted partners, such as YouTube and Google Video, is converted into a WordPress shortcode when a post is saved.


I assume you talk about widget in general sense and not WordPress Widget.

In what form would you like to offer your widget to WordPress users?

  • straight JS snippet might work if used in WordPress Text Widget or post/page content, but might get broken as well - most of input/output in WP is heavily scrubbed for security;
  • you can wrap it in PHP function as snippet for functions.php;
  • you can package it as full plugin and offer usage as function call or shortcode.

Also wp_enqueue_script() is mandatory reading for working with JS in WP.

It all depends on how you want to handle it, your PHP skills and skills of your target WP users (the less savvy they are the more stuff you will have to take care of).

  • My Javascript spits out iframe content. That iframe in itself contains full small page which works based on jQuery etc. As I mentioned this code works on plain vanilla html pages. I know ruby/rails but do not know both wordpress and PHP. Can you elaborate on how to wrap it in functions.php ? Sep 15, 2010 at 4:07
  • functions.php is file in WordPress themes used for code tweaks and snippets. Had you first tried WP text widget with your code? Making whole plugin out of this might be long story and overkill if you aren't working with WP/PHP.
    – Rarst
    Sep 15, 2010 at 5:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.