custom_background()
将CSS放置到wp_head()
正如你提到的那样,让那些CSS看起来好像你没有wp_head()
在标题中,核心文件中的这些调整将有助于:
function wpse_228588_background_image_css() {
$background_styles = \'\';
if ( $bgcolor = get_background_color() )
$background_styles .= \'background-color: #\' . $bgcolor . \';\';
$background_image_thumb = get_background_image();
if ( $background_image_thumb ) {
$background_image_thumb = esc_url( set_url_scheme( get_theme_mod( \'background_image_thumb\', str_replace( \'%\', \'%%\', $background_image_thumb ) ) ) );
// Background-image URL must be single quote, see below.
$background_styles .= \' background-image: url(\\\'\' . $background_image_thumb . \'\\\');\'
. \' background-repeat: \' . get_theme_mod( \'background_repeat\', get_theme_support( \'custom-background\', \'default-repeat\' ) ) . \';\'
. \' background-position: top \' . get_theme_mod( \'background_position_x\', get_theme_support( \'custom-background\', \'default-position-x\' ) );
}
return $background_styles; // CSS
}
用法:
<style type="text/css" media="all">body{<?php echo wpse_228588_background_image_css(); ?>}</style>