首页 文章

php文件不会覆盖wordpress子主题

提问于
浏览
0

我有一个焕然一新的高级主题 . 我为未来的保护创造了一个儿童主题 . 我想覆盖文件 parent-theme/framework/shortcodes/widgets.php 中的一个函数,该函数定义为:

function wt_shortcode_recent_posts($atts) {
  //some code here
}
add_shortcode('wt_recent_posts', 'wt_shortcode_recent_posts');

现在,在我的子主题的functions.php中,我试图将函数覆盖为:

function wt_shortcode_recent_posts($atts) {
   //some modified code here
}

我也尝试将文件创建为与 child-theme/framework/shortcodes/widgets.php 相同的目录 . 它也行不通 .

在wordpress子主题中覆盖这些函数或php文件的正确方法是什么 .

1 回答

  • 1

    您必须覆盖短代码功能 . 将以下内容添加到您的子主题functions.php中

    function some_new_shortcoe_function($atts) {
        // New shortcode code here
    }
    
    remove_shortcode('wt_recent_posts');   
    add_shortcode('wt_recent_posts', 'some_new_shortcode_function');
    

相关问题