仅在WordPress简码页面上调用JS方法



我想调用一个js方法,只有该页面包含我在函数不应执行的另一页短代码上传递的相同短代码......

例如,我在不同的页面上有两个短代码。 当我转到第 2 页时,触发了第 1 页短代码方法并在控制台日志中返回错误,指出找不到某些 ID......

看看代码

注意我正在使用 Gulp

我的第一个代码

第一个简码 JS

class EmiCalculator {
//construct
constructor() {
this.calculateEMI();
this.events();
this.footerTitle();
}

this.calculateEMI((; 当我转到其他类型错误时返回错误:document.getElementById(...( 为空

所以我想当我得到另一个页面时,我想要这个.calculateEMI((; 方法不触发...

你可以注册一个js脚本文件,比如-

wp_register_script( 'js-name',plugin_dir_url( __FILE__ ) .'assets/js/yourfile.js',array ('jquery'),'',true );

之后,您可以在简码功能中排队。 你可以像这样添加-

function shortcode() {
wp_enqueue_script('js-name');
//code
}

最新更新