简体   繁体   English

无法将脚本排入子主题

[英]Unable to Enqueue Scripts in Child Theme

I'm attempting to register and enqueue a script from a javascript file in a child theme. 我试图从子主题中的javascript文件中注册脚本并使其入队。 The script appears to register just fine, returning true, however nothing happens when the script is enqueued. 脚本似乎注册得很好,返回true,但是将脚本放入队列后什么也没有发生。 Are there any problems with the way I am registering or enqueueing? 我的注册或入队方式是否有问题?

In functions.php, I'm checking the user's role, and registering and enqueuing scripts from custom_functions.js if that user has the role of 'ad_greensboro'. 在functions.php中,我要检查用户的角色,如果该用户具有'ad_greensboro'角色,则从custom_functions.js注册和排队脚本。

function tutor_portal_scripts() {
    $user = wp_get_current_user();
    if (in_array( 'ad_greensboro', (array) $user->roles ) ) {
        debug_to_console("User is AD Greensboro");
        wp_register_script('set_rollup_links_greensboro', get_stylesheet_directory_uri() . '/js/custom_functions.js', array(jquery), '', true);
        wp_enqueue_script('set_rollup_links_greensboro');
    } 
}
add_action( 'wp_enqueue_scripts', 'tutor_portal_scripts' );

Below is the entire contents of my custom JS file. 以下是我的自定义JS文件的全部内容。 Its purpose is to change the href property for three links on a specific page. 其目的是更改特定页面上三个链接的href属性。

 function set_rollup_links_greensboro() { console.log("Set rollup links for Greensboro AD"); var at_link = document.getElementById('at-view-link'); var bas_link = document.getElementById('bas-view-link'); var tutor_link = document.getElementById('tutors-view-link'); at_link.setAttribute('href', 'https://devts.techstartutors.com/appointment-tracker-form-view-greensboro-nc/'); bas_link.setAttribute('href', 'https://devts.techstartutors.com/book-a-service-form-view-greensboro-nc/'); tutor_link.setAttribute('href', 'https://devts.techstartutors.com/'); } 

Thanks in advance. 提前致谢。

In your javascript file, you should call that function. 在您的javascript文件中,您应该调用该函数。 So add the following code to the end of your javascript file: 因此,将以下代码添加到javascript文件的末尾:

set_rollup_links_greensboro();

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

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