Title: Javascript Plugin Development (external JS files vs wp_enqueue_script)
Last modified: August 31, 2016

---

# Javascript Plugin Development (external JS files vs wp_enqueue_script)

 *  [TakiToney](https://wordpress.org/support/users/takichicken/)
 * (@takichicken)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/javascript-plugin-development-external-js-files-vs-wp_enqueue_script-1/)
 * Hi, I’m developing a plugin for work and I’m basically learning how to develop
   plugins for the first time. I have a question about using javascript hardcoded
   in the main php file for the plugin and linking to the external javascript files.
 * Basically I can use document.write() if I hard code it into the plugin but, if
   I try to use wp_enqueue_script the javascript works but, document.write doesn’t
   seem to work.
 * So this works
 *     ```
       echo '<h1>Clean Post Search Settings</h1></p>
       <p>		<h2>Add/Edit Topics</h2>';?><br />
       		<script><br />
       		document.open();<br />
       		document.write("<h1>Main title</h1>");<br />
       		document.close();<br />
       		</script></p>
       <p>
       ```
   
 * But, document.write doesn’t work here
 * PHP
 *     ```
       </p>
       <p>function cps_zt_settings_page(){<br />
       	echo '<h1>Clean Post Search Settings</h1></p>
       <p>		<h2>Add/Edit Topics</h2>';<br />
       		wp_enqueue_script(cps_zt_js);<br />
       }<br />
       ```
   
 * External Javascript file
 *     ```
       <br />
       document.open();<br />
       document.write("<h1>Hello World</h1>");<br />
       document.close();<br />
       ```
   

Viewing 1 replies (of 1 total)

 *  [ancawonka](https://wordpress.org/support/users/ancawonka/)
 * (@ancawonka)
 * [9 years, 12 months ago](https://wordpress.org/support/topic/javascript-plugin-development-external-js-files-vs-wp_enqueue_script-1/#post-7415992)
 * Take a look at the examples on the wp_enqueue_scripts documentation page: [https://developer.wordpress.org/reference/functions/wp_enqueue_script/](https://developer.wordpress.org/reference/functions/wp_enqueue_script/)
 * When using wp_enqueue_script, you are letting WordPress decide where to put your
   included script file, and in what order relative to other scripts that are included
   in the page.
 * Before the script can be enqueued, WordPress needs to know where to find the 
   file. Did you register the script somewhere earlier? (using wp_register_script)?
 * If you call wp_enque_script in the middle of rendering the page, your script 
   should be added at the bottom of the page. Do you see a script tag showing the
   full URL to your script file at the bottom of the page?

Viewing 1 replies (of 1 total)

The topic ‘Javascript Plugin Development (external JS files vs wp_enqueue_script)’
is closed to new replies.

## Tags

 * [external-javascript](https://wordpress.org/support/topic-tag/external-javascript/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [plugin-development](https://wordpress.org/support/topic-tag/plugin-development/)
 * [wp_enqueue_script](https://wordpress.org/support/topic-tag/wp_enqueue_script/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [ancawonka](https://wordpress.org/support/users/ancawonka/)
 * Last activity: [9 years, 12 months ago](https://wordpress.org/support/topic/javascript-plugin-development-external-js-files-vs-wp_enqueue_script-1/#post-7415992)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
