2

generates the css file with the php file

 2 years ago
source link: https://www.codesd.com/item/generates-the-css-file-with-the-php-file.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

generates the css file with the php file

advertisements

I'm building a wordpress theme options page using the redux framework. I read al the data in my style.php file and i will include that file in de header so the custom css is loaded.

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>

Now its all messy in the head of my website. It would be great if it automatically generates a css file. Does anyone know a good option?


You can define your PHP file as a CSS file by writing header("Content-type: text/css"); at the start.

<?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'];?>;
}
...

If you do so you can link it with <link rel="stylesheet" type="text/css" href="css/style.php"> in header.php


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK