2012-06-05 37 views
0

好吧,我試圖消除所有可能的變量進行故障排除。因此,而不是在我的functions.php,我在我的header.php文件掉了這個代碼:我的新方法wp_enqueue_script

<?php $mdgtemplateloc = get_bloginfo('template_url').'/js/'; ?> 
<?php echo '<!-- ' . $mdgtemplateloc . ' --> ?> 
<?php wp_enqueue_script('hoverIntent', $mdgtemplateloc.'hoverIntent.js', array('jquery')); ?> 
<?php wp_enqueue_script('mdMenuAnimation', $mdgtemplateloc.'mdMenuAnimation.js', array('hoverIntent')); ?> 

結果是幾個空格插入到源和要求出現的註釋。我的理解是,這將插入類似

<script type="text/javascript" src="[url]/js/mdMenuAnimation.js"></script> 

我想這個做正確的方式,但wp_enqueue_script一直給我什麼。我懷疑我正在做一些根本性錯誤的事情,但我找不到它,並且沒有發現通過谷歌或stackoverflow或wp codex幫助。

爲了澄清,這是我收到了,在functions.php文件:

function mdg_setup_scripts() { 
    $mdgtemplateloc = get_bloginfo('template_url').'/js/'; 
    wp_register_script('hoverIntent', get_bloginfo('template_url').'/js/hoverIntent.js', array('jquery')); 
    wp_enqueue_script('hoverIntent'); 
    wp_register_script('mdMenuAnimation', $mdgtemplateloc.'mdMenuAnimation.js', array('hoverIntent')); 
    wp_enqueue_script('mdMenuAnimation'); 
} 
add_action('wp_enqueue_scripts', 'mdg_setup_scripts'); 

這也沒有產生輸出有史以來稱爲腳本。我明白,這一秒更像是應該是什麼,但它沒有做任何事情。

回答

2

wp_enqueue_script()不輸出任何東西。你使用不正確。

您需要創建一個回調並將其添加到wp_enqueue_scripts操作。通常這屬於您的functions.php文件。

重新閱讀文檔。有些例子正是你想要做的。

+0

是的,這是: '<?php function my_scripts_method(){ wp_deregister_script('jquery'); wp_register_script('jquery','http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'); wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts','my_scripts_method'); ?>' 要放在functions.php中。我這樣做,並且我得到相同的確切行動(當然,取代我自己的腳本名稱/位置)。 –

+0

你使用'wp_head()'嗎? –

+0

是的,但沒有'