0
我是wordpress新手。我創建了一個插件,它工作正常。現在我改變了我的wordpress主題(創建了我自己的主題)。問題是插件中的js文件不包括何時主題是我的主題。 js文件包含在其他主題中。我該怎麼做才能解決這個問題。
我用下面的代碼在插件的第一頁加載Jquery的
js文件不包含在wordpress主題中
add_action('init', 'register_script');
function register_script() {
wp_register_script('custom_jquery', plugins_url('/js/bootstrap.js', __FILE__), array('jquery'), '2.5.1');
wp_register_script('custom_jquery1', plugins_url('/js/jquery.min.js', __FILE__), array('jquery'), '2.5.1');
wp_register_script('cust_pluginjs1', plugins_url('/js/pluginjs.js', __FILE__), array('jquery'), '2.5.1');
wp_register_style('new_style', plugins_url('/css/style.css', __FILE__), false, '1.0.0', 'all');
wp_register_style('new_style1', plugins_url('/css/bootstrap.css', __FILE__), false, '1.0.0', 'all');
wp_register_style('new_style2', plugins_url('/css/font-awesome.css', __FILE__), false, '1.0.0', 'all');
wp_localize_script('cust_pluginjs1', 'myAjax', array('ajaxurl' => admin_url('admin-ajax.php')));
}
add_action('wp_enqueue_scripts', 'enqueue_style');
function enqueue_style(){
wp_enqueue_script('custom_jquery');
wp_enqueue_script('custom_jquery1');
wp_enqueue_script('cust_pluginjs1');
wp_enqueue_style('new_style');
wp_enqueue_style('new_style1');
wp_enqueue_style('new_style2');
}
了jQuery的js文件使用的是
function domainsort(type)
{
// jQuery.post('http://localhost/wptest/wp-admin/admin-ajax.php',data)
jQuery.ajax({
type: 'POST',
url: myAjax.ajaxurl,
data: {
action: 'sortfn',
sortId: type,
},
success:function(data){
if(data){
jQuery(".tablenpage").html(data);
}
},
error: function(MLHttpRequest, textStatus, errorThrown){
alert(errorThrown);
}
});
}
你有jquery庫加載在functions.php? –
@KeesSonnema我已經加載Jquery插件的第一頁。我將用該代碼更新該問題。 – Salini
你有沒有試過這個:'if(typeof jQuery =='undefined'){ //警告某事。 } –