【问题标题】:How to update WordPress theme files with child theme如何使用子主题更新 WordPress 主题文件
【发布时间】:2019-04-24 14:59:50
【问题描述】:

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

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

目前该主题的子版本在网站上处于活动状态。我是否缺少让我的实时网站反映更改的过程?此外,在 Chrome 开发者工具中,我尝试更新的文件的文件名末尾有 ?ver=3.17.6。

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案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');
    

    【讨论】:

    • 您好 Ovidiu,您的解决方案完美运行!我真的很感激帮助。我假设将在 CSS 方面执行类似的程序?通过子主题进行了哪些更改?
    • 我现在在执行此操作后再次更改 JavaScript 文件时遇到问题。所以它可以更新原始父文件。但是,现在我不能再次更新它了吗?为什么WordPress是这样的..
    猜你喜欢
    • 2017-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多