Title: How to enqueue some javascript source
Last modified: August 21, 2016

---

# How to enqueue some javascript source

 *  [colingoldbergatmacmicro](https://wordpress.org/support/users/colingoldbergatmacmicro/)
 * (@colingoldbergatmacmicro)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/how-to-enqueue-some-javascript-source/)
 * Hi,
 * I need my plugin to generate two things – once on the page:
 * 1) Using wp_enqueue_script() – this is done
    <script type=”text/javascript” src
   =”[https://<url&gt](https://<url&gt);.js”></script>
 * 2) What can I use to generate a piece of javascript initialization code that 
   should only appear once on the page
 * eg.
    <script type=”text/javascript”> ritc.initialize(‘63864593a4153879’); </script
   >
 * Is there anything like wp_enqueue_script() but which takes a string instead of
   a url?
 * Thanks in anticipation.
 * Colin G

Viewing 1 replies (of 1 total)

 *  Thread Starter [colingoldbergatmacmicro](https://wordpress.org/support/users/colingoldbergatmacmicro/)
 * (@colingoldbergatmacmicro)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/how-to-enqueue-some-javascript-source/#post-3696571)
 * I have re-written the post to be more clear. Here’s the re-write:
 * I need my plugin to generate the following – once per page:
 *     ```
       <script type="text/javascript" src="https://<ritc url for js file>"></script>
       <script type="text/javascript">
       ritc.initialize('63864593a4153879');
       </script>
       ```
   
 * The purpose of this is to allow one or more shortcodes – all requiring the same
   initialization – to be on a page. I can use wp_enqueue_script() in the shortcode
   function – this works for the first line ie.
 * `<script type="text/javascript" src="https://<ritc url for js file>"></script
   >`
 * But how do I generate the next lines to follow – and only once on the page? ie.
 *     ```
       <script type="text/javascript">
       ritc.initialize('63864593a4153879'); (one line within script tags)
       </script>
       ```
   
 * Is there anything like wp_enqueue_script() but which takes a string instead of
   a url? The string would be the one-liner above. Not to forget the dependency 
   on the first line above.
 * Or should I just generate the javascript from the shortcode function, managing
   it so it only appears once in the page? (How do I do this? Is there a global 
   variable I can use?)
 * Or is there another approach to doing this?
 * Thanks in anticipation.
 * Colin G

Viewing 1 replies (of 1 total)

The topic ‘How to enqueue some javascript source’ is closed to new replies.

## Tags

 * [initialization](https://wordpress.org/support/topic-tag/initialization/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * 1 reply
 * 1 participant
 * Last reply from: [colingoldbergatmacmicro](https://wordpress.org/support/users/colingoldbergatmacmicro/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/how-to-enqueue-some-javascript-source/#post-3696571)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
