【发布时间】:2018-03-06 07:51:25
【问题描述】:
我有一个简单的问题。我正在制作 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
我尝试重命名该函数,使其不会被重新声明,但这并没有解决问题。到目前为止,我还没有真正为我的主题添加任何额外的代码。我还模仿了与父主题相同的目录结构:
资产 函数.php 公司 custom_header.php 索引.php ...
这是我目前拥有的文件:
Functions.php
<?php
函数二十七个孩子入队样式(){ $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
/** * 自定义标头实现 * * @链接https://codex.wordpress.org/Custom_Headers * * @package WordPress * @subpackage Twenty_Seventeen * @since 1.0 */
/** * 设置 WordPress 核心自定义标题功能。 * * @使用二十七个_header_style() */ 函数二十七自定义标题设置(){
/**
* 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-image Default image of the header.
* @type string $default_text_color Default color of the header text.
* @type int $width Width in pixels of the custom header image. Default 954.
* @type int $height Height in pixels of the custom header image. Default 1300.
* @type string $wp-head-callback Callback function used to styles the header image and text
* displayed on the blog.
* @type string $flex-height Flex 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' );
?>
【问题讨论】:
标签: php wordpress wordpress-theming