4

I want to insert external JavaScript placed in the folder in WordPress. if I include using script tag it shows "<" expected error below is my code

global $wpdb; 
include("/asset/php/chart4php/inc/chartphp_dist.php"); 

$p = new chartphp(); 

$p->data_sql = $wpdb->get_results("select t2.name, count(t1.id) as score from custom_status as t2 left join wpsp_ticket as t1 on t2.name =    t1.status group by t2.name");

$p->chart_type = "bar"; 

// Common Options 
$p->title = "Category Sales"; 
$p->xlabel = "Category"; 
$p->ylabel = "Sales"; 

 $color = array("#1AAF5D","#F2C500","#F45B00","#8E0000","#0E948C"); 
 $p->color = $color[rand(0,4)]; 

 $out = $p->render('c1'); 

Tried including js files

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'ajax_search' );
wp_register_script( 'chartphp', plugins_url('/asset/php/chart4php/chartphp.js', __FILE__), array('jquery'));

wp_enqueue_script( 'chartphp' );

Also I want to include 3 move files

<script src="/asset/php/chart4php/jquery.min.js"></script> 
<script src="/asset/php/chart4php/chartphp.js"></script> 
<link rel="stylesheet" href="/asset/php/chart4php/chartphp.css"> 

enter image description here

2 Answers 2

2

I haved added external javascript in the past by using:

wp_register_script( 'validation', 'https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ) );

wp_enqueue_script( 'validation' );

From what I can see, you are not enqueuing the script after you register it in WP.

Also double check your plugin url path is correct as an extra measure.

Sign up to request clarification or add additional context in comments.

6 Comments

Does plugins_url('/asset/php/chart4php/chartphp.js' go to the file? Have you tried the path in the browser to see if it links? Also are you still getting the "<" expected error?
how to check that its gng to url are not.yes still getting error
I would echo plugins_url('/asset/php/chart4php/chartphp.js', FILE); Then see if you can go to that url. If not, you might not be linking to the JS file correctly. If that works, you'll need to do a little more debugging as the screenshot you have added does not tell us where the error is breaking from.
Even I am bit confused from where I am getting error....if I add other script also same error...
if i do echo it says page not found error echo plugins_url('/asset/php/chart4php/chartphp.js', FILE);
|
2

The correct way to include scripts in WordPress is using wp_enqueue_script().

If you previously registered the script you can simply reference it:

You could either link a script with a handle previously registered using the wp_register_script() function, or provide this function with all the parameters necessary to link a script.

Note that if you include default scripts such as jQuery in the dependencies parameter, you don't need to register and/or enqueue them separately.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.