Custom css in external file
Hi,
I understand how to include custom css in front-end with <style> tag. My question is: is it possible include the same css code in an external file (custom.php)?
<link rel='stylesheet' id='custom-css' href='mypath/custom.php' type='text/css' media='all' />
I tried to do it but my file is empty... I remember that in SMOF you could do it.
Good question. Was about to create a new thread asking the same thing. I also need a style-css.php where I will print color codes etc.
So far I have this in functions.php:
wp_register_style( 'style-css', get_template_directory_uri() . '/style-css.php', array(), false, 'all' ); wp_enqueue_style( 'style-css' );
And the contents of style-css.php are:
// change header to css
header("Content-type: text/css");
global $goldenworks; ?>
.fd1 {
background:;
}
.fd2 {
background:;
}
.fd3 {
background:;
}
But it doesn't work. The $goldenworks['fdecbg-left'], etc are empty. Of course I could do this instead and it will work:
.fd1 {
background:;
}
.fd2 {
background:;
}
.fd3 {
background:;
}
But using wp-load.php is a very bad practice that will highly increase the loading time and will slow down the site, so I am looking for a good alternative. Also since I am working on a Themeforest wordpress theme, Themeforest might reject the theme for using wp-load.php.
External css file with php variables is vital for a wordpress theme to have nowadays but it's something often overlooked.
Hopefully Dovy can give us a helping hand and recommend an elegant solution :)
By the way can someone tell how to properly wrap the code ? I tried both pre and code tags but none work properly.
Are these values you want to derive from what the user enters in the panel? Have you looked up the compiler hook? ;)
http://reduxframework.com/docs/advanced/compiler/
@dovy I'd thought to compiler hook but I haven't understood how to implement it. Should I put the function that creates the static css (like SMOF method) in to testCompiler function for example?
The absolute best thing do do is to use the compiler hook to generate a CSS file that you actually save using the FileSystem API. That way you're not using resources on every page load.
So I'd pass all your css into a variable, then output that to a file. ;)
This has the benefit of being able to be cached too.
If that makes sense, then I'll close this for now. If you need further help, don't hesitate to ping me. ;)
@alvisir You may want to see this: https://github.com/ReduxFramework/redux-converter
Is there no easy way to get an external css file with php like "style.css.php" with redux variables work? That would be the ultimate boost for the Redux Framework!
Hello ! The post is old but i found how to use $globals Redux on css.php file :-)
On start your php css wrote this line : define('WP_USE_THEMES', false); require('../../../../wp-load.php'); //change path in your level :-)
header("Content-type: text/css; charset: UTF-8"); $variableFooterColor = $GLOBALS['redux_demo']['opt-color-footer'];
/* write css and use php variables */
Enjoy