如何使用wp_enqueue_script从WordPress插件导入脚本和样式

时间:2016-08-18 17:47:18

标签: php jquery css wordpress

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

谢谢。 Ossai Emmanuel C

2 个答案:

答案 0 :(得分: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

的直接引用

答案 1 :(得分:0)

您可能需要拨打主题wp_head()部分底部的<head></head>。插件会挂钩到wp_head操作,以使用wp_enqueue_script()wp_enqueue_style()添加其脚本和样式。 wp_head()基本上会触发wp_head操作。所以只需像这样添加wp_head()

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

以下是wp_headhttps://codex.wordpress.org/Plugin_API/Action_Reference/wp_head

的参考资料
相关问题