简体   繁体   中英

How to load Javascript via wp_enqueue_script in Wordpress?

I would like to add in the following Javascript into a Wordpress site.

This needs to go in before the closing Head tag:

<SCRIPT LANGUAGE="JavaScript" SRC="http://remote.romancart.com/js/roc_button.asp?storeid=38781"></script>

and this needs to go just before the closing Body tag:

<script>ROC_buttonWidget('ROC_widget','38781',113,0);</script>

I believe you need to add this in via a wp_enqueue_script . Being a newbie, I'm not sure how to write that. Can someone help?

Thanks

Check out the Function reference for wp_enqueu_script .

You can also add scripts manually, just as a less recommended alternative:

From the Wordpress dashboard, go to Appearance > Editor and select the Header Template among the template files on the right. This will bring up the code of the header template. Locate </head> and paste your code just before (that's the closing head tag).

The closing body tag ( </body> ) should be in the footer template ( footer.php ). Look for that template and locate the tag. Then paste your code just before it.

<SCRIPT LANGUAGE="JavaScript" SRC="http://remote.romancart.com/js/roc_button.asp?storeid=38781"></script> add in header.php file in your theme root folder. **if file found in your theme folder**
and
<script>ROC_buttonWidget('ROC_widget','38781',113,0);</script> and this add on footer.php file on your theme folder. **if file found in your theme folder**
function scripts_styles() {
$in_header = false;
$in_footer = true;

// Add javascript in header
wp_enqueue_script( 'script-id', 'http://remote.romancart.com/js/roc_button.asp?storeid=38781', array( 'jquery' ), '', $in_header );

// Add javascript in footer
wp_enqueue_script( 'script-id', 'http://remote.romancart.com/js/roc_button.asp?storeid=38781', array( 'jquery' ), '', $in_footer ); }

add this script in functions.php and use action wp_enqueue_scripts .
add_action( 'wp_enqueue_scripts', 'scripts_styles' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM