如何让我的脚本在wordpress中工作

How to get my script working in wordpress

本文关键字:wordpress 工作 脚本 我的      更新时间:2023-09-26

我有一个相当复杂的脚本,它使用谷歌地理位置API和时区API,我想把它集成到我的wordpress页面中。该脚本包括显示谷歌地图。

从哪里开始?我尝试将代码粘贴到 wordpress 页面代码编辑器中,但这不起作用。

在页面的 head 部分包含 JS 库和 JS 函数。例如,您可以通过将代码添加到 WP 模板的标头.php文件中来执行此操作。

此页面上的示例 4 应该会有所帮助。

你应该使用 wp_enqueue_script 函数来包含你的 JS 脚本。有关此功能的详细信息,请查看此 Codex 页面 : http://codex.wordpress.org/Function_Reference/wp_enqueue_script

如果只想在指定页面上加载此脚本,则应使用条件标记:http://codex.wordpress.org/Conditional_Tags#The_Conditions_For_...

if ( is_front_page() && is_home() ) {
    // Default homepage
} elseif ( is_front_page() ) {
    // static homepage
} elseif ( is_home() ) {
    // blog page
} else {
    //everything else
}