Title: JavaScript not rendering in custom widget
Last modified: August 20, 2016

---

# JavaScript not rendering in custom widget

 *  Resolved [SamHodges](https://wordpress.org/support/users/samhodges/)
 * (@samhodges)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-not-rendering-in-custom-widget/)
 * Hi Guys,
 * I’ve been using wordpress now for a couple of years as a leech basically just
   consuming content, and i recently came up with an idea for a plugin related to
   my workplace… I am now trying to reproduce and advert widget basically which 
   pulls in widgets generated by a 3rd party.
 * I have created a stement thatis supposed to throw out the JS if a statement is
   true, but i cant seem to make the JS render in my widget, the same code works
   in the HTML javascript adder widget but not mine… any ideas?
 *     ```
       if( $type == 'skyscraper'){
       			$widget = '<div id="FusePress"><div id="widget-26-W0bc2803a495" style="overflow: visible;"></div><script language="javascript" type="text/javascript" src="http://www.click-trail.co.uk/feed-distribution/lastminute/dp/uk/widgets/ws1/6.php?pid=4654843&fpwid=W0bc2803a495"></script></div>';
       		}
       ```
   
 * Thanks,
 * Sam

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

 *  Thread Starter [SamHodges](https://wordpress.org/support/users/samhodges/)
 * (@samhodges)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-not-rendering-in-custom-widget/#post-2556978)
 * Dont suppose anyone has a solution r.e. this? Im guessing it must be a relativley
   easy problem but i cant seem to find the answer anywhere…
 * Sam
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-not-rendering-in-custom-widget/#post-2556979)
 * You need to enqueue your javascript.
    [http://codex.wordpress.org/Function_Reference/wp_enqueue_script](http://codex.wordpress.org/Function_Reference/wp_enqueue_script)
 *  Thread Starter [SamHodges](https://wordpress.org/support/users/samhodges/)
 * (@samhodges)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-not-rendering-in-custom-widget/#post-2556980)
 * Thanks, i actually came up witht hat answer myself after a little more digging.
   I get the concept but im guessing my execution is an orderof magnitue out… Because
   the if statement has several other else’s attached i have to load the url of 
   the JS dynamically so i defined a function to decide what to load after it has
   decided which type to call. After that i pass that in then try and echo out the
   JS after, im guessing this is not the correct way of doing things?
 *     ```
       function load_url(){
       			wp_enqueue_script( load_url, $widget_url);
       		}	
   
       if( $type == 'skyscraper'){
       			$widget_url = 'http://www.click-trail.co.uk/feed-distribution/lastminute/dp/uk/widgets/ws1/6.php?pid=4654843&fpwid=W0bc2803a495';
       			add_action('wp_enque_scripts', 'load_url');
       			$widget = '<div id="widget-26-W0bc2803a495" style="overflow: visible;"></div><script language="javascript" type="text/javascript" src="http://www.click-trail.co.uk/feed-distribution/lastminute/dp/uk/widgets/ws1/6.php?pid=4654843&fpwid=W0bc2803a495"></script>';
   
       		}
   
       echo $widget;
       ```
   
 * Sorry im very special..
 *  Thread Starter [SamHodges](https://wordpress.org/support/users/samhodges/)
 * (@samhodges)
 * [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-not-rendering-in-custom-widget/#post-2556983)
 * Very special indeed, that function does solve it!
 * Incredibly rookie case sensativity mistake!

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

The topic ‘JavaScript not rendering in custom widget’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 4 replies
 * 2 participants
 * Last reply from: [SamHodges](https://wordpress.org/support/users/samhodges/)
 * Last activity: [14 years, 4 months ago](https://wordpress.org/support/topic/javascript-not-rendering-in-custom-widget/#post-2556983)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
