WordPress 子主题覆盖父主题包括 [英] WordPress child theme override a parent theme include

查看:32
本文介绍了WordPress 子主题覆盖父主题包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 WordPress 子主题,需要覆盖某些小部件模板.我正在尝试使用此方法来覆盖父主题调用:The Right覆盖主题功能的方法.

I'm creating a WordPress child theme and need to overwrite certain widget templates. I'm trying to use this method to override the parent theme call: The Right Way to Override Theme Functions.

但是,我目前收到此错误:

However, I currently get this error:

致命错误:无法重新声明 hickory_homepage_load_widget()(之前声明于C:\wamp\www\greenpeaceNewBlog\wp-content\themes\gp-blog\inc\widgets\homepage_widget.php:8)在C:\wamp\www\greenpeaceNewBlog\wp-content\themes\hickory\inc\widgets\homepage_widget.php第 10 行

Fatal error: Cannot redeclare hickory_homepage_load_widget() (previously declared in C:\wamp\www\greenpeaceNewBlog\wp-content\themes\gp-blog\inc\widgets\homepage_widget.php:8) in C:\wamp\www\greenpeaceNewBlog\wp-content\themes\hickory\inc\widgets\homepage_widget.php on line 10

父主题functions.php像这样调用模板:

The parent theme functions.php calls the templates like this:

include("inc/widgets/homepage_widget.php");

homepage_widget.php 文件包含以下内容:

The homepage_widget.php file contains this:

add_action( 'widgets_init', 'hickory_homepage_load_widget' );

function hickory_homepage_load_widget() {
    register_widget( 'hickory_homepage_widget' );
}

我有一个子主题重复小部件目录(stylesheet_directory/inc/widgets/..)和一个子主题functions.php.在我的孩子functions.php中,我写了这个:

I have a child theme duplicate widget directory (stylesheet_directory/inc/widgets/..) and a child theme functions.php. In my child functions.php, I have written this:

// Remove the default Thematic blogtitle function
function remove_hickory_widgets() {
    remove_action('widgets_init', 'hickory_homepage_load_widget');
}

// Call 'remove_thematic_actions' (above) during WP initialization
add_action('init','remove_hickory_widgets');

include("inc/widgets/homepage_widget.php");

请帮忙:)

干杯

推荐答案

试试这个

add_action( 'init', 'remove_hickory_widgets' );

function remove_hickory_widgets() {
    remove_action('widgets_init', 'hickory_homepage_load_widget' );
    add_action( 'init', 'custom_widgets' );
}

function custom_widgets(){
    // your widget code here
}

这篇关于WordPress 子主题覆盖父主题包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆