Modify site URL via functions.php of a theme

My site URL in the database shows Is it possible to change this via functions.php into, however still maintaining in the database?

My current scenario is that I have three developers who work locally and we want to use one database. We all connect to a remote database, however, the URLs from our local development environment and from the remote database are different which causes broken links.

Is there some way to change the siteurl in functions.php while still having the same URL in the database?

Thanks in advance.

Solutions Collecting From Web of "Modify site URL via functions.php of a theme"

The theme_root_uri filter will allow the URLs returned by get_stylesheet_directory_uri() and get_template_directory_uri() to be altered on the fly:

 * Filters the URI for themes directory.
 * @since 1.5.0
 * @param string $theme_root_uri         The URI for themes directory.
 * @param string $siteurl                WordPress web address which is set in General Options.
 * @param string $stylesheet_or_template Stylesheet or template name of the theme.
function wpse_theme_root_uri( $theme_root_uri, $siteurl, $stylesheet_or_template ) {
    // $siteurl will be via get_option( 'siteurl' )
    return str_replace( $siteurl, '', $theme_root_uri );
add_filter( 'theme_root_uri', 'wpse_theme_root_uri', 10, 3 );

The plugins_url filter will allow the URL returned by plugin_dir_url() to be altered in a similar fashion:

 * Filters the URL to the plugins directory.
 * @since 2.8.0
 * @param string $url    The complete URL to the plugins directory including scheme and path.
 * @param string $path   Path relative to the URL to the plugins directory. Blank string
 *                       if no path is specified.
 * @param string $plugin The plugin file path to be relative to. Blank string if no plugin
 *                       is specified.
function wpse_plugins_url( $url, $path, $plugin ) {
    return str_replace( get_option( 'siteurl' ), '', $url );
add_filter( 'plugins_url', 'wpse_plugins_url', 10, 3 );

Looking through /wp-includes/link-template.php, there are quite a few other functions that return URLs, but they can be filtered using the same approach as demonstrated above.

The values for the options siteurl and home can be modified on the fly as well:

function wpse_pre_option_siteurl_and_home( $pre_option, $option ) {
    return '';
add_filter( 'pre_option_siteurl', 'wpse_pre_option_siteurl_and_home', 10, 2 );
add_filter( 'pre_option_home',    'wpse_pre_option_siteurl_and_home', 10, 2 );

This shouldn’t be handled by your theme at all, but your local wp-config.php file. You can conditionally load local and unique wp-config definitions by wrapping in a conditional file_exists. Here’s an example from Mark Jaquith:

if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
    include( dirname( __FILE__ ) . '/local-config.php' );
    define( 'WP_LOCAL_DEV', true ); // We'll talk about this later
} else {
    define( 'DB_NAME',     'production_db'       );
    define( 'DB_USER',     'production_user'     );
    define( 'DB_PASSWORD', 'production_password' );
    define( 'DB_HOST',     'production_db_host'  );

See here for more details:

If instead of modifying functions.php you can modify wp-config.php, you can use the following: