Skip to content

Instantly share code, notes, and snippets.

@fastmover
Created May 14, 2015 02:18
Show Gist options
  • Select an option

  • Save fastmover/72878a1303d8c5b61c12 to your computer and use it in GitHub Desktop.

Select an option

Save fastmover/72878a1303d8c5b61c12 to your computer and use it in GitHub Desktop.
Live Reload Theme functions for Wordpress and Grunt-contrib-watch
<?php
function removePortFromURL ( $url = false )
{
if ( ! $url ) {
return false;
}
$url = rtrim ( $url, '/' );
$url = rtrim ( $url, ':' );
$urlNoHTTP = substr ( $url, 0, -strpos ( $url, ':' ) );
if ( false !== strpos ( $urlNoHTTP, ':') ) {
$url = substr ( $url, 0, strrpos ( $url, ':' ) );
}
return $url;
}
function liveReload( $dev ) {
if ( true === $dev ) {
$url = removePortFromURL ();
?>
<script src="<?= $url; ?>:35729/livereload.js"></script>
<?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment