我正在使用redux框架构建一个wordpress主题选项页面。我在我的style.php文件中读取了所有数据,并将在de header中包含该文件,以便加载自定义的CSS。
style.php:
<?php
?>
body {
background-color:<?php global $variable; echo $variable['color-background'];?>;
font-family:<?php global $variable; echo $variable['typography6']['font-family'];?>;
}
a {
color: <?php global $variable; echo $variable['link-color']['regular'];?>;
}
<?php
?>
header.php:
<style>
<?php require_once('css/style.php');?>
</style>
现在,一切都乱七八糟了。如果它自动生成一个css文件,那就太好了。有谁知道一个不错的选择?
最佳答案
您可以通过在开始时编写header("Content-type: text/css");
将PHP文件定义为CSS文件。
<?php
header("Content-type: text/css");
?>
body {
background-color:<?php global $variable; echo $variable['color-background'];?>;
font-family:<?php global $variable; echo $variable['typography6']['font-family'];?>;
}
...
如果这样做,可以将其与
<link rel="stylesheet" type="text/css" href="css/style.php">
中的header.php
链接关于php - 用php文件生成css文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22129576/