2014-05-15 29 views
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); 
       } 
      }); 
} 
+0

你有jquery庫加載在functions.php? –

+0

@KeesSonnema我已經加載Jquery插件的第一頁。我將用該代碼更新該問題。 – Salini

+0

你有沒有試過這個:'if(typeof jQuery =='undefined'){ //警告某事。 } –

回答

0

你在這裏完全註冊/入列錯誤。您註冊一個函數腳本,你勾init,然後排隊他們在另一個函數的掛鉤,爲wp_enqueue_scripts

你應該有你的wp_register_script(),並在同一個函數wp_enqueue_script(),然後該函數要被掛鉤到wp_enqueue_scripts

編輯

你絕不能使用init掛鉤排隊腳本或樣式。使用正確的鉤子是wp_enqueue_scripts

相關問題