0

如何确定是否调用了 Wordpress 主题文件?例如,每次加载archive.php时,我想有条件地在页脚添加一个js文件。

我目前在functions.php中使用类似的东西来加载全局js。如何调整以便根据调用的 Wordpress 文件加载额外的 js?

//Use Google CDN to load jQuery
function use_google_jquery() {
    if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', false, '1.7.2', true);
        wp_enqueue_script('jquery');

        // load a JS file from my theme: js/default.js
        wp_enqueue_script('my_script', get_bloginfo('template_url') . '/js/default.js', array('jquery'), '1.0', true);      
    }   }   add_action('init', 'use_google_jquery');

编辑和注意: 特定 Wordpress 页面上的 JS适用于给定页面,但我正在寻找给定模板文件,例如 archive.php 并加载到页脚中。

4

1 回答 1

2

使用以下函数 is_single()、is_archive()、is_page()、is_home()

于 2012-05-15T15:09:32.807 回答