Skip to content

Instantly share code, notes, and snippets.

@jnthnclrk
Last active December 20, 2015 15:49
Show Gist options
  • Save jnthnclrk/6157540 to your computer and use it in GitHub Desktop.
Save jnthnclrk/6157540 to your computer and use it in GitHub Desktop.
En-queue scripts & styles for Bootstrap and Less.js in WordPress
<?php
/**
* Enqueue scripts and stylesheets
*/
function enqueue_less_styles($tag, $handle) {
global $wp_styles;
$match_pattern = '/\.less$/U';
if ( preg_match( $match_pattern, $wp_styles->registered[$handle]->src ) ) {
$handle = $wp_styles->registered[$handle]->handle;
$media = $wp_styles->registered[$handle]->args;
$href = $wp_styles->registered[$handle]->src . '?ver=' . $wp_styles->registered[$handle]->ver;
$rel = isset($wp_styles->registered[$handle]->extra['alt']) && $wp_styles->registered[$handle]->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
$title = isset($wp_styles->registered[$handle]->extra['title']) ? "title='" . esc_attr( $wp_styles->registered[$handle]->extra['title'] ) . "'" : '';
$tag = "\r\n";
}
return $tag;
}
add_filter( 'style_loader_tag', 'enqueue_less_styles', 5, 2);
function hyp_enqueue_scripts() {
if ( !is_admin() ) {
wp_enqueue_style('less', get_template_directory_uri() . '/style.less', false, null);
wp_register_script( 'lessjs', get_template_directory_uri() . '/js/less-1.4.1.min.js', false, null );
wp_enqueue_script( 'lessjs' );
wp_enqueue_style('bpl-styles', get_template_directory_uri() . '/style.css', false, null);
// jQuery is loaded in header.php using the same method from HTML5 Boilerplate:
// Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline
// It's kept in the header instead of footer to avoid conflicts with plugins.
wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');
wp_register_script( 'bootstrap-js', get_template_directory_uri() . '/bootstrap/js/bootstrap.min.js', false, null, true );
wp_enqueue_script( 'bootstrap-js' );
}
}
add_action('wp_enqueue_scripts', 'hyp_enqueue_scripts', 100);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment