使用选项页(ACF)生成动态css

使用选项页(ACF)生成动态css,css,wordpress,advanced-custom-fields,Css,Wordpress,Advanced Custom Fields,我目前正在为wordpress开发一个选项页面(ACF Pro v5),该页面可以动态生成css文件。当我在本地进行测试时,它运行良好;只有在实时服务器上,动态css不能由wordpress生成 我错过什么了吗?wordpress有没有写文件的权限。我将一个干净的custom-style.css与chmod 777一起放在正确的文件夹中 这是我在functions.php中编写的代码: function generate_options_css() { $ss_dir = get_stylesh

我目前正在为wordpress开发一个选项页面(ACF Pro v5),该页面可以动态生成css文件。当我在本地进行测试时,它运行良好;只有在实时服务器上,动态css不能由wordpress生成

我错过什么了吗?wordpress有没有写文件的权限。我将一个干净的custom-style.css与chmod 777一起放在正确的文件夹中

这是我在functions.php中编写的代码:

function generate_options_css() {
$ss_dir = get_stylesheet_directory();
ob_start(); // Capture all output into buffer
require($ss_dir . '/styles.php'); // Grab the custom-style.php file
$css = ob_get_clean(); // Store output in a variable, then flush the buffer
file_put_contents($ss_dir . '/Library/css/custom-styles.css', $css, LOCK_EX); // Save it as a css file
} add_action( 'acf/save_post', 'generate_options_css' ); //Parse the output and write the CSS file on post save
wp_enqueue_style( 'custom-styles', get_template_directory_uri() . '/Library/css/custom-styles.css' );

可能是您的live server正在使用子主题运行,而您的本地安装程序没有子主题。这就是为什么您的本地版本工作,而live不工作的原因。最可能的原因是您同时使用了函数
get\u template\u directory\u uri()
get\u stylesheet\u directory()'/Library/css/custom styles.css'
文件


因此,明智的做法是根据您的需求使用任何一个,而不是同时使用两个:)

此库文件夹存储在哪里,其chmod值是多少?@radscheit位于主题文件夹的根目录中,我已手动将chmod更改为777。什么也没发生。代码似乎是正确的。PHP日志记录失败了吗?