如何使用子主题更新WordPress主题文件

时间:2018-11-22 00:24:43

标签: wordpress wordpress-theming

我正在尝试通过FTP对WordPress主题进行更改,并且它似乎没有在实时网站上更新。 在这种情况下,我对JavaScript文件进行了更改:

../wp-content/themes/Divi/includes/builder/scripts/frontend-builder-global-functions.js

当前,该主题的子版本在网站上处于活动状态。我是否需要一个流程来使我的实时网站反映这些变化?另外,在Chrome开发人员工具中,我尝试更新的文件的文件名末尾有?ver = 3.17.6。

1 个答案:

答案 0 :(得分:1)

最简单的方法是将已更新的JavaScript文件从父级复制到子主题的文件夹中,然后在子主题functions.php文件中使用内置的WordPress函数wp_deregister_script和wp_register_script。您的代码应如下所示:

function new_child_script() {
// De-register the Divi default theme script
wp_deregister_script('frontend-builder-global'); //check the name of the default script in page source

// Register the updated script from the child theme
wp_register_script('frontend-builder-global-custom-script', get_template_directory_uri() . '/js/frontend-builder-global-functions.js', 
array('jquery'));

// Enqueue the script
wp_enqueue_script('frontend-builder-global-custom-script');
}

 add_action('wp_enqueue_scripts', 'new_child_script');
相关问题