Functions.php code that only runs on localhost?

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');

3 s
3

This is the corect answer

if ( $_SERVER["SERVER_ADDR"] == '127.0.0.1' ) {
    function livereload(){
    ?>
        // mycode
     <?php
    }
    add_action('headway_body_close', 'livereload');
}

Leave a Comment