我有一个快速的问题。我正在努力使Twentyseventeen主题成为子主题, 并且试图覆盖custom_header代码, 但出现以下错误:
PHP Fatal error:Cannot redeclare twentyseventeen_custom_header_setup() (previously declared in /Applications/MAMP/htdocs/wordpress/wp-content/themes/twentyseventeen/inc/custom-header.php:36) in /Applications/MAMP/htdocs/wordpress/wp-content/themes/twentyseventeen/inc/custom-header.php on line 52
我尝试重命名该函数, 因此不会重新声明它, 但不能解决问题。到目前为止, 我还没有真正在主题中添加任何其他代码。我还模仿了目录结构, 使其与父主题相同:
资产functions.php inc custom_header.php index.php …
这是我到目前为止拥有的文件:
Functions.php
<
?php
函数二十十七岁儿童_enqueue_styles(){$ parent_style =’ parent-style’ ;
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style )
);
}
add_action( 'wp_enqueue_scripts', 'twentyseventeenchild_enqueue_styles' );
/**
* Implement the Custom Header feature.
*/
require get_parent_theme_file_path( '/inc/custom-header.php' );
?>
custom_header.php
<
?php
/ ** *自定义标头实现* * @link https://codex.wordpress.org/Custom_Headers * * @package WordPress * @subpackage Twenty_Seventeen * @始于1.0 * /
/ ** *设置WordPress核心自定义标头功能。 * * @使用二十岁十七岁的人的头衔()* /函数二十岁十七岁的客户的头衔(){
/**
* Filter Twenty Seventeen custom-header support arguments.
*
* @since Twenty Seventeen 1.0
*
* @param array $args {
*An array of custom-header support arguments.
*
*@type string $default-imageDefault image of the header.
*@type string $default_text_colorDefault color of the header text.
*@type int$widthWidth in pixels of the custom header image. Default 954.
*@type int$heightHeight in pixels of the custom header image. Default 1300.
*@type string $wp-head-callbackCallback function used to styles the header image and text
*displayed on the blog.
*@type string $flex-heightFlex support for height of header.
* }
*/
add_theme_support( 'custom-header', apply_filters( 'twentyseventeen_custom_header_args', array(
'default-image'=>
get_parent_theme_file_uri( '/assets/images/header.jpg' ), 'width'=>
2000, 'height'=>
1200, 'flex-height'=>
true, 'video'=>
true, 'wp-head-callback'=>
'twentyseventeen_header_style', ) ) );
register_default_headers( array(
'default-image' =>
array(
'url'=>
'%s/assets/images/header.jpg', 'thumbnail_url' =>
'%s/assets/images/header.jpg', 'description'=>
__( 'Default Header Image', 'twentyseventeen' ), ), ) );
}
add_action( 'after_setup_theme', 'twentyseventeen_custom_header_setup' );
?>
#1【WordPress自定义标题-错误】在我发布问题之后。我要做的就是将这段代码添加到我的functions.php中
$custom_header_args = array(
'default-image' =>
get_theme_file_uri( '/assets/images/header.jpg' ), 'width' =>
2000, 'height' =>
1200, 'flex-height' =>
true, 'video' =>
true, );
add_theme_support('custom-header', $custom_header_args);
推荐阅读
- WordPress(通过过滤器自定义Ajax请求响应)
- 将Adsense代码添加到header.php后,WordPress CSS无法加载
- WordPress自定义3级超级菜单
- 运用万能5笔输入法打不出火星文的处理办法
- WinRAR自动压缩、加密的设置办法
- WinRAR文件分卷压缩技巧运用办法
- WinRAR自动备份文件技巧的运用办法
- 百度输入法输入特殊标记办法_百度输入法
- 必应输入法怎样样?必应输入法的11个特色技巧介绍