redux-framework icon indicating copy to clipboard operation
redux-framework copied to clipboard

Custom css in external file

Open alvisir opened this issue 13 years ago • 9 comments

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.

alvisir avatar Nov 12 '13 09:11 alvisir

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 :)

Goldenworks avatar Nov 12 '13 12:11 Goldenworks

By the way can someone tell how to properly wrap the code ? I tried both pre and code tags but none work properly.

Goldenworks avatar Nov 12 '13 12:11 Goldenworks

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 avatar Nov 12 '13 13:11 dovy

@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?

alvisir avatar Nov 12 '13 14:11 alvisir

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.

dovy avatar Nov 12 '13 14:11 dovy

If that makes sense, then I'll close this for now. If you need further help, don't hesitate to ping me. ;)

dovy avatar Nov 13 '13 01:11 dovy

@alvisir You may want to see this: https://github.com/ReduxFramework/redux-converter

dovy avatar Dec 21 '13 00:12 dovy

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!

ghost avatar Oct 12 '16 16:10 ghost

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

zebulondev avatar Jun 29 '20 18:06 zebulondev