You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**WordPress Dynamic CSS** is a lightweight library for generating CSS stylesheets from dynamic content (i.e. content that can be modified by the user). The most obvious use case for this library is for creating stylesheets based on Customizer options. Using the special dynamic CSS syntax you can write CSS rules with variables that will be replaced by static values using a custom callback function that you provide.
35
+
**WordPress Dynamic CSS** is a lightweight library for generating CSS stylesheets from dynamic content (i.e. content that can be modified by the user). The most obvious use case for this library is for creating stylesheets based on Customizer options. Using the special dynamic CSS syntax you can write CSS rules with variables that will be replaced by static values using a custom callback function that you provide.
33
36
**As of version 1.0.2** this library supports multiple callback functions, thus making it safe to use by multiple plugins/themes at the same time.
Then, create a file called `my-style.css` and write this in it:
59
+
Then, create a file called `my-style.css` and write your (dynamic) CSS in it:
57
60
58
61
```css
59
62
body {
@@ -201,6 +204,37 @@ body {
201
204
}
202
205
```
203
206
207
+
## API Reference
208
+
209
+
### wp_dynamic_css_enqueue
210
+
211
+
*Enqueue a dynamic stylesheet*
212
+
213
+
```php
214
+
function wp_dynamic_css_enqueue( $handle, $path, $print = true )
215
+
```
216
+
217
+
This function will either print the compiled version of the stylesheet to the document's <head> section, or load it as an external stylesheet if `$print` is set to false.
218
+
219
+
**Parameters**
220
+
*`$handle` (*string*) The stylesheet's name/id
221
+
*`$path` (*string*) The absolute path to the dynamic CSS file
222
+
*`$print` (*boolean*) Whether to print the compiled CSS to the document head, or load it as an external CSS file via an http request
223
+
224
+
### wp_dynamic_css_set_callback
225
+
226
+
*Set the value retrieval callback function*
227
+
228
+
```php
229
+
function wp_dynamic_css_set_callback( $handle, $callback )
230
+
```
231
+
232
+
Set a callback function that will be used to convert variables to actual values. The registered function will be used when the dynamic CSS file that is associated with the name in `$handle` is compiled. The callback function accepts 1 parameter which is the name of the variable, without the $ sign.
233
+
234
+
**Parameters**
235
+
*`$handle` (*string*) The name of the stylesheet to be associated with this callback function.
236
+
*`$callback` (*callable*) A callback (or "callable" as of PHP 5.4) can either be a reference to a function name or method within a class/object.
237
+
204
238
## TODO
205
239
206
240
*~~Add support for loading the compiled CSS externally instead of printing to the document head~~ (Added in 1.0.1)
0 commit comments