I would like to run an add_action in functions.php only if the theme is being loaded from my localhost development site. How would I get this to run only on localhost?
function livereload(){
?>
// mycode
<?php
}
add_action('headway_body_close', 'livereload');
This is the corect answer
A rather safe way is marking your local environment as such in your local
wp-config.php
.Example:
This is also a question of readability. You can see immediately what the code does.
The easiest way to do it to check IP address of an user. If it equals to 127.0.0.1, then this user running the site on localhost.
UPDATE: or as mentioned @Tommixoft you can check server IP address.