默认情况下,WordPress使用_custom_background_cb()
函数创建问题中显示的样式。您可以将自己的函数添加到add_theme_support()
在您的主题中。
add_theme_support( \'custom-background\', array( \'wp-head-callback\' => \'wpse_113346_custom_background_cb\' ) );
最初,您可以使用
_custom_background_cb()
功能为您自己的功能:
/**
* My custom background callback.
*/
function wpse_113346_custom_background_cb() {
// $background is the saved custom image, or the default image.
$background = set_url_scheme( get_background_image() );
// $color is the saved custom color.
// A default has to be specified in style.css. It will not be printed here.
$color = get_theme_mod( \'background_color\' );
if ( ! $background && ! $color )
return;
$style = $color ? "background-color: #$color;" : \'\';
if ( $background ) {
$image = " background-image: url(\'$background\');";
$repeat = get_theme_mod( \'background_repeat\', \'repeat\' );
if ( ! in_array( $repeat, array( \'no-repeat\', \'repeat-x\', \'repeat-y\', \'repeat\' ) ) )
$repeat = \'repeat\';
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( \'background_position_x\', \'left\' );
if ( ! in_array( $position, array( \'center\', \'right\', \'left\' ) ) )
$position = \'left\';
$position = " background-position: top $position;";
$attachment = get_theme_mod( \'background_attachment\', \'scroll\' );
if ( ! in_array( $attachment, array( \'fixed\', \'scroll\' ) ) )
$attachment = \'scroll\';
$attachment = " background-attachment: $attachment;";
$style .= $image . $repeat . $position . $attachment;
}
?>
<style type="text/css" id="custom-background-css">
body.custom-background { <?php echo trim( $style ); ?> }
</style>
<?php
}
此时,您应该测试它以确保它正常工作。测试完成后,您可以开始更改
wpse_113346_custom_background_cb()
根据您的喜好自定义输出。