使用wp_add_inline_style方式添加背景图片

Published
May 11, 2022
浏览次数 :  1

/display the hero image on the background
function gymfitness_hero_image() {
$front_page_id = get_option( ‘page_on_front’ );
$image_id = get_field(‘hero_image’,$front_page_id);

$image = $image_id[‘url’];

//creat a false stylesheet
wp_register_style( ‘custom’,false );
wp_enqueue_style(‘custom’);

$featured_image_css = “

body.home .site-header {
background-image:url($image);
}

“;

wp_add_inline_style( ‘custom’, $featured_image_css );
}
add_action(‘init’,’gymfitness_hero_image’);


Top