我试图通过函数将内联样式的css注入到我的body元素中。php文件。它需要内联,因为我使用ACF让用户更改图像。
结果应该是:
<body style="background-image: url(\'<?php the_field(\'background\'); ?>\');">
我读到关于wp add inline style, 但我想不出来。更新:以下是我尝试的函数:
function wpdocs_styles_method() {
wp_enqueue_style(\'custom-style\', get_stylesheet_directory_uri() . \'/body.css\'
);
$img = get_theme_mod( "<?php the_field(\'background\') ?>" );
$custom_css = "body {background-image: {$img}";
wp_add_inline_style( \'custom-style\', $custom_css );
}
add_action( \'wp_enqueue_scripts\', \'wpdocs_styles_method\' );
我确实装了一具尸体。css尝试添加内联css。但它没有起作用——也许这根本不是正确的方法?