简体   繁体   English

如何将脚本添加到WordPress页面

[英]how to add the script to the wordpress page

I am trying to create the appear and disappear effect as found on this page http://dante.swiftideas.net/developer-documentation , there are three scripts getting fired jquery-1.9.1.js, jquery-ui.js and then there is a third script without a name. 我正在尝试创建此页面http://dante.swiftideas.net/developer-documentation上的出现和消失效果,有三个脚本被触发jquery-1.9.1.js,jquery-ui.js,然后第三个脚本没有名称。 So how to add the third script to a specific wordpress page? 那么如何将第三个脚本添加到特定的wordpress页面?

use the wp_enqueue_script() function inside your theme's functions.php - it's meant to be used for this purpose. 在主题的functions.php中使用wp_enqueue_script()函数-旨在用于此目的。 If you only want this script to load on a single specific page, then you can wrap the wp_enqueue_script function with a conditional to check if it's that specific page (by the page's ID in wordpress): 如果只希望将此脚本加载到单个特定页面上,则可以使用条件包装wp_enqueue_script函数,以检查是否是该特定页面(通过wordpress中的页面ID):

if (is_page(123)) {
    function theme_name_scripts() {
        wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true ); }
    }
    add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM