If instead of modifying functions.php you can modify wp-config.php, you can use the following:
define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');
Source: https://codex.wordpress.org/Changing_The_Site_URL#Edit_wp-config.php