Last active
January 21, 2016 00:40
-
-
Save jakebellacera/8950261 to your computer and use it in GitHub Desktop.
Scripts List - PHP managed scripts list
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 | |
// Default scripts | |
$script_list = array( | |
'vendor/jquery.js', | |
'vendor/bootstrap.js', | |
'vendor/video.js', | |
'`videojs.options.flash.swf = "' . get_bloginfo('stylesheet_directory') . '/assets/swf/videojs.swf"', | |
'global.js' | |
); | |
// Add custom scripts to your page | |
// | |
// Usage: | |
// Set a var named $scripts as an array with path (relative from either the | |
// /assets/css dir or as a separate URL for external scripts) into the | |
// array in the order that you want. Code snippets can be added as well as | |
// long as the string starts with a backtick (`). | |
// | |
// Example: | |
// $scripts = array('foo.js', '//bar.com/baz.js'); | |
// | |
// Additonal Features: | |
// Removing Scripts - If you want to remove a script that, you can do so by | |
// prepending your script name with a bang ("!"). | |
// | |
// Example: | |
// $script = array('foo.js', '!bar.js'); | |
// | |
// The example above will add the script "foo.js" and | |
// remove the script "bar.js" if it was already going | |
// to be loaded. | |
if (isset($scripts)) { | |
foreach ($scripts as $script) { | |
if (preg_match('/^\!/', $script)) { | |
$index = array_search(substr($script,1), $script_list); | |
if ($index) { | |
unset($script_list[$index]); | |
} | |
} else { | |
array_push($script_list, $script); | |
} | |
} | |
} | |
foreach ($script_list as $script) { | |
if (preg_match('/^`/', $script)) { | |
echo '<script type="text/javascript">' . substr($script, 1) . '</script>'; | |
} else { | |
if (preg_match('/^((http(s?):)?)\/\//', $script)) { | |
echo "<script type=\"text/javascript\" src=\"$script\"></script>\n"; | |
} else { | |
echo '<script type="text/javascript" src="'. get_bloginfo('stylesheet_directory') .'/assets/js/'. $script ."\"></script>\n"; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
instead of echoing script tags, be better off using wp_enqueue_script