开发者 |
Askupa Software
ykadosh |
---|---|
更新时间 | 2016年12月26日 01:46 |
PHP版本: | 3.0 及以上 |
WordPress版本: | 4.7 |
版权: | GPLv3 or later |
版权网址: | 版权信息 |
functions.php
file:
// 1. Load the library (skip this if you are loading the library as a plugin)
require_once 'wp-dynamic-css/bootstrap.php';
// 2. Enqueue the stylesheet (using an absolute path, not a URL)
wp_dynamic_css_enqueue( 'my_dynamic_style', 'path/to/my-style.css' );
// 3. Set the callback function (used to convert variables to actual values)
function my_dynamic_css_callback( $var_name )
{
return get_theme_mod($var_name);
}
wp_dynamic_css_set_callback( 'my_dynamic_style', 'my_dynamic_css_callback' );
// 4. Nope, only three steps
Then, create a file called my-style.css
and write this in it:
body {
background-color: $body_bg_color;
}
In the above example, the stylesheet will be automatically compiled and printed to the of the document. The value of $body_bg_color
will be replaced by the value of get_theme_mod('body_bg_color')
.
Now, let's say that get_theme_mod('body_bg_color')
returns the value #fff
, then my-style.css
will be compiled to:
body {
background-color: #fff;
}
There's even support for array subscripts and piped filters:
body {
background-color: $myVar['index'];
color: $myVar|myFilter;
}
You can find detailed documentation on how to use this library on the GitHub page
Useful Links