52

You are asking two questions at once: What's the difference between home_url() and site_url()? How do I get WordPress to return the URL root without the subdirectory where it's installed? Here are the answers, and I confirmed with Andrew Nacin, a core developer of WordPress, as well as ran some server tests to confirm what Andrew told me. Question # 1 In ...


22

If this is a single WordPress install, there are a couple database entries with your old domain. Specifically, siteurl and home within wp_options. That said, if the dev URL is temporary, you can also set the following two constants in wp-config.php: define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); define('WP_SITEURL', WP_HOME . '/'); Provided that ...


12

You can get the value of front in the global $wp_rewrite: global $wp_rewrite; echo $wp_rewrite->front; // or echo home_url( $wp_rewrite->front ); Though that is probably of limited use, as the front base isn't necessarily an existing page, and may 404 in many cases. If you're using that value to prepend to other URLs, you're likely doing it wrong. ...


10

You can try these: 1. make sure the values changed in database If you can't login to wp-admin > settings to confirm that, you can go to database, wp_options table and look for siteurl and home values 2. add code to wp-config.php Add these lines to wp-config.php define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); 3. Clear ...


9

You could filter the option requests for the host. In your wp-config.php below the line … require_once ABSPATH . 'wp-settings.php'; … add the following lines: add_filter( 'pre_option_home', 'set_current_host' ); add_filter( 'pre_option_siteurl', 'set_current_host' ); function set_current_host() { return 'http://' . $_SERVER['HTTP_HOST']; } ...


7

There's a pretty good step by step on moving WordPress in the Codex. It is what I follow when changing domains. Moving the files is pretty straight-forward. It is the hard-coded references in the database that are tricky. However, serialized search and replace will take care of all database changes. I've used the Velvet Blues plugin in the past, but ...


7

If anyone out there has a similar situation as me, I found a solution by adding: /* That's all, stop editing! Happy blogging. */ /** Absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); /* THIS IS CUSTOM CODE CREATED AT ZEROFRACTAL TO MAKE SITE ACCESS DYNAMIC */ $currenthost = "http://".$_SERVER[...


7

I usually just avoid the issue entirely every time I create a new wordpress site: define('WP_HOME', '/'); define('WP_SITEURL', '/'); will cause wordpress to use root-relative urls for everything. Makes site migrations to other domains far easier. Ofc, if you access your site using a folder (eg. "http://<domain>/blog") you could change them to: ...


6

I had the same issue. To fix it I had to make some changes to the database. Use phpMyAdmin or just log directly into the database and look at your wp_options table. Check the following two fields: siteurl and home. SELECT * FROM wp_options WHERE option_name IN ('siteurl', 'home'); Make sure these fields hold the correct domain information if not change ...


5

You can filter domain_exists, a check that runs before a site is registered. If you return a positive integer, WordPress will not create that site. Despite its name, that filter lets you check the path too. Sample code, not tested: add_filter( 'domain_exists', function( $result, $domain, $path ) { // Already taken, no need for further checks. if ( ...


4

The site_url() and home_url() functions are similar and can lead to confusion in how they work. The site_url() function retrieves the value value for siteurl in the wp_options table in your database. This is the URL to the WordPress core files. If your core files exist in a subdirectory /wordpress on your web server, the value would be http://example....


4

The difference in your case is in filters being applied to output of these functions. While bloginfo applies one of these filters: if ( 'display' == $filter ) { if ( $url ) $output = apply_filters('bloginfo_url', $output, $show); else $output = apply_filters('bloginfo', $output, $show); } Function home_url ...


4

I believe there are some root-links that you haven't changed. Please follow these steps Login to admin section www.xyz.com/wp-admin Navigate to settings->general-> and change the 'Site Address (URL)' and 'WordPress Address (URL)'. Also please check the permalinks and settings->media there is an upload directory and the default wordpress location is wp-...


4

This question has been discussed several times on the WordPress Hackers email list, I'd recommend Googling something like wp-hackers absolute relative to get an overview of the various lively debates that have taken place over the years. Personally I use the searchreplacedb2 script whenever I migrate a database between URLs, e.g. from live to local/test/dev....


4

I utilize the awesome plugin Duplicator to complete this exact procedure on a regular basis. http://wordpress.org/extend/plugins/duplicator/ The plugin is fully supported and there are great FAQ available here: http://lifeinthegrid.com/labs/duplicator/ The plugin will create a .zip backup of both your database and files and an installer .php that you ...


4

It is not a big problem. Your Database contains all previous links which cannot be automatically converted. There are two type of solutions for that: In wp-config.php add this code: define('WP_HOME', 'http://' . $_SERVER['SERVER_NAME']); define('WP_SITEURL', WP_HOME . '/'); Change the following SQL by replacing "oldurl" with the previous link and "newurl" ...


4

I was about to suggest something like the function bellow, but lets face it @Milo's answer is just a bit smarter, so just for completeness reason and because I already wrote it down. function wpse163163_site_url_with_fix_permalink_base() { return get_site_url() . '/' . preg_replace( '/\%([a-z0-9]+?)\%/i', ...


4

Wordpress will always redirect to the canonical URL of the content if you try to access a page not with its canonical url. If you installed wordpress without using a www then wordpress will assume that the root url for the install is without www. Or in other words, wordpress is not actively removing www, it is just a by-product of eliminating possibility of ...


4

Check your .htaccess file for the proper values. Here's what WP recommends; you may need to adjust for your configuration (from here; more examples that might help) https://codex.wordpress.org/htaccess # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f ...


4

This is a classical case. All you need to do is to use Rewrite Rules. With Apache, you can do it in .htaccess: # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress ...


4

Google wants to see that you have ownership of the domain, because on some sites, subscribers have the ability to upload to the media library. You'll need to upload the file using FTP/SFTP to the domain's root folder (i.e. public_html or www). You should be able to get these from your hosting provider. Sometimes they can also upload the file for you.


3

You will have a few things to consider (later on the answer), I suggest the following steps: Backup your Files and Database This is pretty self-explanatory. You are going to do a lot of Data Manipulation, so be sure your original is safe. Transfer your files The fastest way to do this is to have a hoster where you can import directories from another ...


3

TLDR: In a non-standard installation, you can place your WordPress files in a subdirectory of your website root. ...and still allow your visitors to visitors to access your WordPress "website" from your site's Domain (root) URL, without appending the subdirectory name: (ie: www.example.com vs www.example.com/wordpress): WP function | wp_options. | WP ...


3

I encountered the same issue: with WordPress multisite, there is no option or setting that defines if a site domain is HTTP or HTTPS. Even after replacing all occurrences in the database, a site visitor can still enter and navigate the site in HTTP, without being redirected to HTTPS. The following simple solution worked for me: I added this mod_rewrite rule ...


3

I think your problem here is the esc_url() function which is used to sanitize a lot of the URLs used in wp-core. If you have a look at the function definition in formatting.php you'll see that the regex in line 2627 is filtering out [ and ]. But fortunately you can also see that in line 2656 there is a filter supplied which allows you to overwrite this ...


3

While www and non-www versions of site are considered kind of same thing from user perspective, technically they are two completely different domains, possibly hosting completely different sites on different servers. Since cookies are domain-specific WP treats them accordingly. It's not impossible to rework this, since cookie-related functions seem to ...


3

You need to update the new URL in the WordPress Address (URL) and Site Address (URL) in General settings. Some of your media may be pointing your old site or may not be available in that case you need to install a plugin named Search and Replace and you need to replace the every occurrence of the old URL with the new one.


3

Below is a small plugin using which you should be able to replace the domain for canonical url to another domain. <?php /* * Plugin Name: WPSE WPSEO Canonical * Plugin URI: http://wordpress.stackexchange.com * Description: Changes canonical url domain. * Author: Sisir * Version: 1.0 * Author URI: http://developerpage.net * **/ add_filter('...


3

get_template_directory() returns a filesystem path-- that is, it returns the path to the file as it would appear if you were browsing it on the local machine via a file browser. Return Values (string) Absolute path to the directory of the current theme (without the trailing slash). https://codex.wordpress.org/Function_Reference/...


3

<?php site_url( $path, $scheme ); ?> Parameters $path: (optional) Path to be appended to the site url. $scheme: (optional) Context for the protocol for the url returned. Setting $scheme will override the default context. Allowed values are 'http', 'https', 'login', 'login_post', 'admin', or 'relative'. It simply overrides the default ...


Only top voted, non community-wiki answers of a minimum length are eligible