• 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 />
  • The topic ‘Javascript Plugin Development (external JS files vs wp_enqueue_script)’ is closed to new replies.