admin管理员组

文章数量:1434380

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"> 

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"> 

Share Improve this question edited Feb 14, 2017 at 12:08 R9102 asked Feb 14, 2017 at 11:22 R9102R9102 7271 gold badge11 silver badges35 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

I haved added external javascript in the past by using:

wp_register_script( 'validation', 'https://ajax.aspnetcdn./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.

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.

本文标签: phpHow to add external javascript in WordPressStack Overflow