Created
November 20, 2014 07:24
-
-
Save ccurtin/32204f21f8df3cf78287 to your computer and use it in GitHub Desktop.
auto-enqueue-scripts
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 | |
//*** FOLLOWING CODE GETS the ENTERED URL from the BROWSER AND MAPS it to CORRECT ROUTER and CHANGES ALL INSTANCES in the PAGES *** // | |
// Gets URL part "subdomain.domain.com:8081" | |
// Don't forget to add the sub-directory location! | |
$wp_ubiquitousDomain = "http://" . $_SERVER['HTTP_HOST'] . "/smith/asb/wordpress/"; | |
update_option( 'siteurl', $wp_ubiquitousDomain); | |
update_option( 'home', $wp_ubiquitousDomain ); | |
?> | |
<?php | |
// AUTOMATICALLY ENQUEUES SCRIPTS THAT ARE CREATED IN the components/js/folder. | |
// Places them in wordpress theme's js folder. Gets all filnames and enques each one. | |
// Disadvantage is telling which ones to place in header or footer and dependencies. Maybe create 2 folders | |
// with different functions to register in header and footer | |
add_action( 'init', 'all_js' ); | |
function all_js(){ | |
add_action( 'wp_enqueue_scripts', 'auto_add_scripts' ); | |
function auto_add_scripts() { | |
foreach(glob(get_template_directory() . '/js/*.js') as $filename){ | |
$filename = basename($filename); | |
// print $filename; ?> | |
<?php | |
wp_register_script($filename, get_template_directory_uri() . '/js/'.$filename, array('jquery'), '1.0', true); | |
wp_enqueue_script($filename); | |
} | |
?> | |
<?php | |
} | |
} | |
?> | |
<?php | |
// Load HTML5 Blank scripts (header.php) | |
function html5blank_header_scripts() | |
{ | |
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) { | |
wp_register_script('conditionizr', get_template_directory_uri() . '/js/lib/conditionizr-4.3.0.min.js', array(), '4.3.0'); // Conditionizr | |
wp_enqueue_script('conditionizr'); // Enqueue it! | |
wp_register_script('modernizr', get_template_directory_uri() . '/js/lib/modernizr-2.7.1.min.js', array(), '2.7.1'); // Modernizr | |
wp_enqueue_script('modernizr'); // Enqueue it! | |
wp_register_script('html5blankscripts', get_template_directory_uri() . '/js/scripts.js', array('jquery'), '1.0.0',false); // Custom scripts | |
wp_enqueue_script('html5blankscripts'); // Enqueue it! | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment