Jelly Bean
Jelly Bean

Reputation: 1219

My WordPress plugin wp_enqueue_scripts won't work

I am working on the following code. I have looked at all the documents regarding wp_enqueue_scripts and wp_register_script I cannot get it my Wp_callApi.js to load.

How can I fix this?

<?php
/*
Plugin name: My webservice
Version: 1.4
Description: Calling Webservice with javascript.
Auther: JellyDevelopment
Author URI: http://jellydevelopments.co.za
Plugin URI: http://jellydevelopments.co.za
*/

add_action( 'wp_enqueue_scripts', 'load_Javascript' );
function load_Javascript() {
    wp_register_script('prefix_script_01', plugins_url( 'Wp_callApi.js', __FILE__ ), array ('jquery'), "2.1", true );  
}

//add_action( 'wp_enqueue_scripts', 'addMy_script' );

function addMy_script() {
 wp_enqueue_scripts( 'Wp_callApi' );
}

add_action( 'woocommerce_payment_complete', 'addMy_script', 10, 1 );

?>

Upvotes: 2

Views: 77

Answers (1)

Shahbaz A.
Shahbaz A.

Reputation: 4356

You have mutliple errors here. Try this version.

<?php
/*
Plugin name: My webservice
Version: 1.4
Description: Calling Webservice with javascript.
Auther: JellyDevelopment
Author URI: http://jellydevelopments.co.za
Plugin URI: http://jellydevelopments.co.za
*/

function load_Javascript() 
{
    wp_enqueue_script( 'prefix_script_01', plugins_url( '/Wp_callApi.js', __FILE__ ), array('jquery') );  
}
add_action( 'wp_enqueue_scripts', 'load_Javascript' );
?>

This will precisely do what you want. It will enqueue a file named Wp_callApi.js to your front end. This file must be residing at the root of this plugin that you write. If you want to add this file to wordpress admin dashboard then you need to change the action. The last line will change to.

add_action( 'admin_enqueue_scripts', 'load_Javascript' );

Upvotes: 1

Related Questions