Skip to content

Instantly share code, notes, and snippets.

@mannieschumpert
Last active December 31, 2015 04:29
Show Gist options
  • Save mannieschumpert/7934810 to your computer and use it in GitHub Desktop.
Save mannieschumpert/7934810 to your computer and use it in GitHub Desktop.
Optionally enqueue LiveReload for local development.
<?php
/**
* Enqueue LiveReload if local install
*
* Assumes livereload.js is in the root folder of your local site
*
* This should be fairly reliable,
* but may need to be changed for some environments
*/
if ( $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ){
add_action( 'wp_enqueue_scripts', 'enqueue_livereload' );
}
function enqueue_livereload(){
wp_enqueue_script( 'livereload', site_url().'/livereload.js', '', NULL );
}
@nathangross
Copy link

I'm having a slight issue with this. I have livereload.js in the root folder, however when I view source, it's looking for it at /wordpress.

I am thinking that it might be the semi-non-standard way I have wordpress installed:

root

wordpress
livereload.js
wp-content

theme

...

I'm not exactly sure if that's the problem or not. Any ideas?

@nathangross
Copy link

I was able to fix my issue by changing site_url() to home_url()

@mannieschumpert
Copy link
Author

Cool. Sorry I missed this.

Yeah, what site_url and home_url reference does indeed depend on individual installation configurations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment