Clarification: 我的默认标题图像不会RE-display (通过单击建议的图像)在使用主题定制器“隐藏图像”选项将其删除后。
我为自定义标题图像添加了主题支持
// Add Theme Support for Custom Header Image
add_theme_support( \'custom-header\',
array(
\'default-image\' => get_template_directory_uri() . \'/assets/img/hdr_earth.jpg\',
\'default-text-color\' => \'#e2f0d6\',
\'header-text\' => true,
\'uploads\' => true,
\'width\' => 1140,
\'height\' => 200,
\'wp-head-callback\' => \'wpfw_style_header\',
)
);
在主题定制器中,我看到(默认)图像显示为:
单击“隐藏图像”按钮,删除了“当前标题”框和“建议”框中的当前标题图像。
And this is where the problem started
当我试图re-add the default image 通过单击“建议”(即默认)图像。。。
图像is displayed 在customizer窗口中但是图像will not save, 因此,图像不会显示在网页上Avar_dump( get_header_image() );
返回的false
, 在读了内核中的函数之后,我看到了if ( \'remove-header\' == $url ) return false;
.
所以avar_dump( get_theme_mods() )
确实显示了\'header_image\' => string \'remove-header\' (length=13)
.
???
。。。现在这是在我添加了默认图像之后and 已保存。
我错过了什么?
整个脚本(custom header.php)
if ( ! function_exists( \'wpfw_custom_header\' ) ) {
function wpfw_custom_header() {
// Add theme Support for Custom Backgrounds
add_theme_support( \'custom-background\',
array(
\'default-color\' => \'#e2f0d6\',
\'default-image\' => get_template_directory_uri() . \'/assets/img/bgp-128x180.jpg\',
)
);
// Add Theme Support for Custom Header Image
add_theme_support( \'custom-header\',
array(
\'default-image\' => get_template_directory_uri() . \'/assets/img/hdr_earth.jpg\',
\'default-text-color\' => \'#e2f0d6\',
\'header-text\' => true,
\'uploads\' => true,
\'width\' => 1140,
\'height\' => 200,
\'wp-head-callback\' => \'wpfw_style_header\',
)
);
} // end wpfw_custom_header()
} // end if
// Hook into the \'after_setup_theme\' action
add_action( \'after_setup_theme\', \'wpfw_custom_header\', 11 );
/**
* ----------------------------------------------
* Callback function for updating header styles
* ----------------------------------------------
*/
if ( ! function_exists( \'wpfw_style_header\' ) ) {
function wpfw_style_header() {
$text_color = get_header_textcolor();
?>
<style type="text/css" id="wpfw-custom-header-styles">
.site-title a.site-title-link {
color: #<?php echo esc_attr( $text_color ); ?>;
}
<?php if ( display_header_text() != true ) : ?>
.site-title {
display: none;
}
<?php endif; ?>
</style>
<?php
} // end wpfw_style_header()
} // end if...
SO网友:CompactCode
老实说,我在自定义程序中有一个使用以下代码的工作标题图像:
Functions.php
/* custom header image */
$headerimage = array(
\'default-image\' => \'%s/images/image1.jpg\',
\'width\' => 1920,
\'height\' => 1080,
\'flex-height\' => false,
\'flex-width\' => true,
\'uploads\' => true,
\'random-default\' => false,
\'header-text\' => true,
\'default-text-color\' => \'\',
\'wp-head-callback\' => \'\',
\'admin-head-callback\' => \'\',
\'admin-preview-callback\' => \'\',
);
add_theme_support(\'custom-header\', $headerimage);
中没有任何内容
customizer.phpWhere i call the header-image :
<header class="site-header">
<div class="row header-home no-gutters" <?php echo \'style="background-image:url(\' . get_header_image() . \');\' . \'background-repeat: no-repeat;
background-position: center; background-size: cover;min-height:100vh">\'; ?>
</div>
</header>
Register default images (显然,这也是functions.php所必需的)
register_default_headers( array(
\'headerimage\' => array(
\'url\' => \'%s/images/image1.jpg\',
\'thumbnail_url\' => \'%s/images/image1.jpg\',
\'description\' => __( \'headerimage\', \'DesignitMultistore\' )
),
) );
SO网友:Eric van Eldik
对于仍有问题的人,您需要的完整代码是:
在你的职责范围内。php:
register_default_headers( array(
\'default-image\' => array(
\'url\' => get_template_directory_uri() . \'/img/header.jpg\',
\'thumbnail_url\' => get_template_directory_uri() . \'/img/header.jpg\',
\'description\' => __( \'Default Header Image\', \'textdomain\' )
),
) );
function yourtheme_custom_header_setup() {
$args = array(
\'default-image\' => get_template_directory_uri() . \'/img/header.jpg\',
\'default-text-color\' => \'000\',
\'width\' => 1200,
\'height\' => 720,
\'flex-width\' => true,
\'flex-height\' => true,
);
add_theme_support( \'custom-header\', $args );
}
add_action( \'after_setup_theme\', \'yourtheme_custom_header_setup\' );
在模板文件(probally header.php)中:
echo(has_header_image() ? get_header_image() : get_theme_support( \'custom-header\', \'default-image\' ));