需要帮助将一些JavaScript代码添加到我的wordpress主题中

Need help adding some JavaScript code into my wordpress theme

本文关键字:我的 wordpress 添加 代码 帮助 JavaScript      更新时间:2023-09-26

你好,我这里有这个脚本,我需要把它放在我当前的wordpress主题中,但我对入队部分感到困惑。我知道我必须将hoverintent javascript保存在我的主题库中,我是否也将函数javascript保存在主题库中?对不起,如果我没有澄清足够,请评论,如果这令人困惑!

jsfiddle.net/ctLevz8L/59/

从fiddle中获取javascript并将其保存到wp-content/themes/mytheme/js/hoverintent.js中。

然后,将以下内容添加到主题的functions.php文件中:

function enqueue_hoverintent {
    //Add the script and jquery-ui to the generated header.
    wp_enqueue_script(
        'my_hoverintent', 
         get_stylesheet_directory_uri() . '/js/hoverintent.js', 
         array('jquery-ui-core')
    );
    //Add the jqueryui css file from Google's CDN since it isn't included with WP
    wp_enqueue_style (
        'googlecdn_jqueryui_style',
         'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css',
    );
}
add_action( 'wp_enqueue_scripts', 'enqueue_hoverintent' );