Widget code is not working on WordPress.com Hosted Blogs

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");
  document.write(url);
</script>

<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);
</script>

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

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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.

  2. 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).