个性化阅读
专注于IT技术分析

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

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

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

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


#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');
赞(0)
未经允许不得转载:srcmini » 如何使用子主题更新WordPress主题文件

评论 抢沙发

评论前必须登录!