Title: Unable to add JS as a widget
Last modified: August 22, 2016

---

# Unable to add JS as a widget

 *  [thebeautyaddictions](https://wordpress.org/support/users/thebeautyaddictions/)
 * (@thebeautyaddictions)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/)
 * Hi,
 * I have received the code from Yahoo Ads and it is a javascript code to add ads
   to my blog [http://www.thebeautyaddictions.uk](http://www.thebeautyaddictions.uk)
 * First, I tried to add it in the text widget, then downloaded PLUGIN HTML JAVA
   SCRIPT ADDER which doesn’t help.
 * Is there any other way i can insert this javascript code into my column??? I 
   cannot really find this place in html code in php files so it is not possible
   either.
 * Please help

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592288)
 * Hi thebeautyaddictions,
 * According to this link (see [https://wordpress.org/support/topic/how-can-i-add-a-chunk-of-javascript-to-the-text-widget?replies=4](https://wordpress.org/support/topic/how-can-i-add-a-chunk-of-javascript-to-the-text-widget?replies=4)),
   as long as you copy/past the entire JavaScript code (including <script></script
   > bits) into the standard Text widget, you should be fine without the need for
   a plugin.
 * So, as recommended in the link, please, if possible, past your JavaScript here
   so we can test it out for you. Oh, and do be sure you’re copying/pasting the 
   entire code! 🙂
 * Hope this helps,
 * Randy
 *  Thread Starter [thebeautyaddictions](https://wordpress.org/support/users/thebeautyaddictions/)
 * (@thebeautyaddictions)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592302)
 * <script><script id=”mNCC” language=”javascript”> medianet_width=’300′; medianet_height
   = ‘250’; medianet_crid=’478379746′; </script> <script id=”mNSC” src=”[http://contextual.media.net/nmedianet.js?cid=8CU1S6G0R&#8221](http://contextual.media.net/nmedianet.js?cid=8CU1S6G0R&#8221);
   language=”javascript”></script>
 * this is what i enter in the text and doesnt work
 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592313)
 * I just tested your code on my WordPress 4.1 site and ended up with nothing being
   displayed. Just like you, right?
 * I asked one of our programmers about simply adding JavaScript to the Text widget
   and he said the following:
 * > Not recommended. JS [JavaScript] belongs in plugins or child themes.
   >  JS is
   > supposed to be enqueued so WP can prevent duplication and control versions,
   > also loading in header/footer as appropriate. Plus, WP manages dependencies,
   > such as this JS file requires jQuery be loaded first, etc. Throwing JS around
   > in the middle can work, but not well. JS does not belong in the sidebar area.
   > JS belongs in included files enqueued in the header or footer of the site via
   > themes or plugins, and the loaded JS can affect elements anywhere on the site.
   > If the service being included requires it be place in line, they may not have
   > the option of doing it right, meaning the service isn’t so flexible. Their 
   > choice whether to hack it in versus finding a better solution. Usually a JS
   > service will have you make an ID element for it to attach to, so you would 
   > for example install the plugin and add in the sidebar a <div id=“myJSserviceWillShowHere”
   > ></div> in the widget[.]
 * So, I’m going to Google around a bit more and see what I can find. Meanwhile,
   I bet, some other way-wiser-than-I person will most likely post something helpful.
   🙂
 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592319)
 * P.S., In the meantime, I just found this handy official link:
 * [http://codex.wordpress.org/Using_Javascript](http://codex.wordpress.org/Using_Javascript)
 * Which says:
 * > JavaScript will work within WordPress. It can be used within WordPress template
   > files in WordPress Themes or Child Themes. JavaScript cannot be added to post
   > content without a special WordPress Plugin that removes the filters that prevent
   > unwanted code within the post content area, for the protection of the user.
 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592345)
 * Well, like you I tested HTML Javascript Adder version 3.9 using WordPress 4.1/
   Twenty Fourteen and still couldn’t see anything within my Text widget. I also
   tried Allow Javascript in Text Widgets version 0.3 and got the same nothing results.
   I am now going to try Enhanced Text Widget 1.4.4, but I have a weird feeling 
   that there may be something wrong with your JavaScript code. Is there anyway 
   you can verify that it indeed works???
 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592352)
 * Just tested Enhanced Text Widget version 1.4.4 which creates its own special 
   Text widget. That too failed to display anything. So, I’m going to stop testing
   for now until I hear back from you regarding the validity of your JavaScript 
   code.
 *  Thread Starter [thebeautyaddictions](https://wordpress.org/support/users/thebeautyaddictions/)
 * (@thebeautyaddictions)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592358)
 * this code is correct for sure.
 * It was provided to me by Yahoo and it is my ad code.
 * It works on the mobile phone though…. so if you open my site on your phone, just
   above the facebook thing you will see ads..
 *  Thread Starter [thebeautyaddictions](https://wordpress.org/support/users/thebeautyaddictions/)
 * (@thebeautyaddictions)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592360)
 * i had similar issue with adsense but adsense has 2 types of codes that you might
   copy and paste…
 * one of them is javascript and the other (dont remember the name) is the one i
   had to copy for ads to work properly
 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592372)
 * Interesting, because I just ran your code through my Mac Chrome 39.0.2171.95 (
   64-bit) View > Developer > JavaScript Console and it reported:
 *     ```
       Uncaught SyntaxError: Unexpected token <message: "Unexpected token <"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }__proto__: ErrorVM105:762 InjectedScript._evaluateOnVM105:695 InjectedScript._evaluateAndWrapVM105:609 Inject
       ```
   
 * But, I really have no idea about JavaScript. That is, sigh, I am just a software
   tester and not a programmer. But, I find it odd that the code only works on a
   mobile device. That’s going to make things kinda difficult to serve both Desktop
   and Mobile users.
 * So, are you saying your code does work on WordPress in a Text widget _as long
   as the user is on a phone_? And, if so, does it work with or without a plugin?
   And if it’s a plugin, then which one(s)?
 *  [Randy Sandberg](https://wordpress.org/support/users/randywsandberg/)
 * (@randywsandberg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592382)
 * Note that I just tested it again on my WordPress 4.1/Twenty Fourteen site using
   no plugin as well as with all three JavaScript related plugins mentioned above
   and could not see anything generated while viewing with my iPhone 4s / iOS 8.1
   via Apple’s iOS Simulator let alone Mac Safari 8.0.2.
 * So, I am baffled and going to let some other person who knows JavaScript take
   over. I will be waiting in the wings though to see what your final solution is.
   Good luck my friend!
 *  [fearnowrath](https://wordpress.org/support/users/fearnowrath/)
 * (@fearnowrath)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592475)
 * try this plugin [https://wordpress.org/plugins/my-shortcodes/](https://wordpress.org/plugins/my-shortcodes/)
   
   it worked for me when other custom js plugins didn’t work. you can add the code
   into it and simply use the shortcode into your wordpress posts sidebar.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Unable to add JS as a widget’ is closed to new replies.

## Tags

 * [adder](https://wordpress.org/support/topic-tag/adder/)
 * [adding](https://wordpress.org/support/topic-tag/adding/)
 * [html](https://wordpress.org/support/topic-tag/html/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [text](https://wordpress.org/support/topic-tag/text/)
 * [widget](https://wordpress.org/support/topic-tag/widget/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 3 participants
 * Last reply from: [fearnowrath](https://wordpress.org/support/users/fearnowrath/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/unable-to-add-javascript-as-a-widget/#post-5592475)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
