php - How to add external javascript in WordPress - Stack Overflow

I want to insert external JavaScript placed in the folder in WordPress.if I include using script tag i

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745621429a4636539.html

相关推荐

  • php - How to add external javascript in WordPress - Stack Overflow

    I want to insert external JavaScript placed in the folder in WordPress.if I include using script tag i

    22天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信