|
<?php |
|
/* |
|
============================================= |
|
Add this stuff to your functions.php |
|
============================================= |
|
*/ |
|
|
|
function livereload_trigger() { |
|
/* |
|
============================================= |
|
Touch a useless file when triggered |
|
============================================= |
|
*/ |
|
$target = get_stylesheet_directory() . '/livereload-trigger.php'; |
|
touch($target); |
|
} |
|
function is_dev(){ |
|
/* |
|
================================================================ |
|
Should return true if you are on a dev site. |
|
I use http://something.dev/ for my local dev so this checks for an occurance |
|
of the string '.dev' in the hostname. |
|
edit this conditional as needed for your own setup |
|
================================================================ |
|
*/ |
|
return stripos($_SERVER['HTTP_HOST'], '.dev') !== false; |
|
} |
|
|
|
/* |
|
================================================================ |
|
Add a listener to the save post action if you're on a dev site. |
|
This gets ignored on prod or other testing sites. |
|
================================================================ |
|
*/ |
|
if(is_dev()){ |
|
add_action( 'save_post', 'livereload_trigger' ); |
|
} |
|
/* |
|
============================================= |
|
Enqueue Scripts |
|
============================================= |
|
*/ |
|
|
|
function add_theme_scripts() { |
|
// Get this from http://modernizr.com and be sure to include the websockets test. |
|
wp_register_script( 'modernizr', trailingslashit(get_template_directory_uri()).'js/vendor/modernizr.full.min.js'); |
|
/* |
|
===== Dev Only Scripts ===== |
|
*/ |
|
if(is_dev()){ |
|
// wp_register_script( 'livereload-loader', "//".$_SERVER['SERVER_NAME'].":35729/livereload.js" ); |
|
wp_register_script( 'livereload-loader', trailingslashit(get_template_directory_uri()).'js/livereload-loader.js', array( 'modernizr' )); |
|
wp_enqueue_script( 'livereload-loader' ); |
|
} |
|
} |
|
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' ); |
|
?> |