2016-08-18 87 views
1

我开发了一个WordPress主题,它工作正常。直到我发现由于主题无法导入插件的样式和脚本,某些插件与主题的效果不佳。那么是否有任何代码可以自动排列我的主题中的任何wordpress插件脚本或样式。我几乎读过关于wp_enqueue_script的所有内容,但仍然无法正常工作。任何帮助将不胜感激。如何使用wp_enqueue_script从WordPress插件导入脚本和样式

谢谢。 Ossai Emmanuel C

+0

直接引用您可以添加必要的代码,以主题functions.php – j08691

回答

0

您可能需要在主题的<head></head>部分的底部呼叫wp_head()。使用wp_enqueue_script()wp_enqueue_style()来将插件挂接到wp_head操作上以添加其脚本和样式。 wp_head()基本上触发wp_head操作。所以只需添加wp_head()这样的:

<html> 
    <head> 
     <!-- Your meta tags here --> 
     <?php wp_head(); ?> 
    </head> 
    <body> 
     <!-- Your html here --> 
    </body> 
</html> 

这里是wp_head参考:https://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

+0

我呼吁wp_head()如你所说,但我仍然无法实现它的工作。欢迎任何帮助。 –

+0

@OssaiEmmanuelC嗯,它应该工作,只要你有wp_head。您是否检查过网站的源代码以确认脚本和样式不在那里? –

+0

@OssaiEmmanuelC另外,也许你可以检查你的PHP错误日志。可能会有一个错误阻止脚本进入队列。 –

1

一些插件他们的脚本加载到尾,而不是<head>。确保你的主题也包含此...

<?php 
    /* Always have wp_footer() just before the closing </body> 
    * tag of your theme, or you will break many plugins, which 
    * generally use this hook to reference JavaScript files. 
    */ 
    wp_footer(); 
?> 
</body> 
</html> 

这是从https://codex.wordpress.org/Function_Reference/wp_footer

+0

这正是我需要的!它像魔术一样工作! –