wp_register_script无法正常工作

问题描述 投票:0回答:1

这不是我的第一个wordpress插件,但我不知道为什么我无法让wp_register_script工作。

如果我只是回显脚本工作(所以我检查了url是正确的)我并不关心deps,因为代码是本机JS。

这是我的代码:

<?php 
/*
Plugin Name: Calculated to paypal
Version: 1.1
Description: Update Paypal Buy now button
Author: Antocorr
Author URI: http://example.com
*/
function calculated_to_paypal_script()
{
    $jsurl = plugins_url() . '/calculated-to-paypal/js/app.js';
    wp_register_script( 'ccp-url', $jsurl, false, NULL, 'all');

}
add_action( 'wp_enqueue_scripts', 'calculated_to_paypal_script' );
?>
php wordpress
1个回答
0
投票

尝试更改以下代码行

$jsurl = plugins_url() . '/calculated-to-paypal/js/app.js';

如下;

$jsurl = plugin_dir_url( __FILE__ ) . '/calculated-to-paypal/js/app.js

或者如下列入或注册脚本;

wp_enqueue_script( 'myscript', plugin_dir_url( __FILE__ ) . '/calculated-to-paypal/js/app.js' );

寄存器

wp_register_script( 'myscript', plugin_dir_url( __FILE__ ) . '/calculated-to-paypal/js/app.js' );

完整的功能代码

使用您的功能如下;

add_action("wp_enqueue_scripts", "myscript");
function myscript() { 
wp_register_script('myjs', plugin_dir_url( __FILE__ ) . '/calculated-to-paypal/js/app.js',
                    array ('jquery', 'jquery-ui'), //try without these first, if fails try adding this line 
                    false, false);
wp_enqueue_script('myscript');

}

© www.soinside.com 2019 - 2024. All rights reserved.