Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanhudak/7235335 to your computer and use it in GitHub Desktop.
Save jonathanhudak/7235335 to your computer and use it in GitHub Desktop.
//functions.php
wp_register_script('livereload', 'http://localhost:35729/livereload.js?snipver=1', null, false, true);
wp_enqueue_script('livereload'); //keep this at the bottom
// this code creates a variable for your template assets path for use with require.js
$WP_DIRECTORY = array( 'path' => get_stylesheet_directory_uri() . '/js' );
wp_localize_script( 'require', 'directory', $WP_DIRECTORY );
// ADD DATA ATTRIBUTE TO ENQUEUE SCRIPT
add_filter('clean_url','requirejs_script',10,2);
function requirejs_script( $url ) {
if ( // comment the following line out add 'defer' to all scripts
FALSE === strpos( $url, 'require.js' )
)
{ // not our file
return $url;
}
// Must be a ', not "!
return "$url' data-main='".get_template_directory_uri()."/js/global'";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment