Last active
August 29, 2015 14:23
-
-
Save brentjett/1f35c4b8bcb2d47319ef to your computer and use it in GitHub Desktop.
Advanced CSS/JS API for WordPress - API Scratchwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Extend wp_enqueue_script & wp_enqueue_style to support callbacks. | |
function beagle_enqueue_style_callback($handle = "script-name", $callback_fun, $callback_args, $enqueue_query = array()) {} | |
beagle_enqueue_style_callback('my-gallery-css', function() { | |
ob_start(); | |
?> | |
body { | |
background:red; | |
color:white; | |
font-size:1.2em; | |
} | |
<?php | |
return ob_get_clean(); | |
}); | |
// same thing for beagle_enqueue_script_callback() | |
/* | |
CSS/JS Stacks - More advanced way to preprocess and concatenate multiple scripts or stylesheets together | |
*/ | |
// 1. Create a "stack" | |
$stack = new Beagle_CSS_Stack(); | |
// 2. Enqueue scripts or stylesheets onto the stack. | |
$stylesheet = new Beagle_Stylesheet('my-css', function() { | |
// return some css in this callback | |
}); | |
$stack->enqueue_stylesheet($stylesheet); | |
// 3. Decide how to output the stack. | |
$stack->output_format = "external" // "external" file or "embed"ed in the <head> | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment