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
2 Answers
Reset to default 2I 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
版权声明:本文标题:php - How to add external javascript in WordPress - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745621428a2666704.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论