Doc WordPress WordPress Tricks, Tips & Snippets

26Mar/170

Fix access problems after domain / site url change

Whenever you need to change the domain under which your WordPress installation is to be found it is necessary to change both the "WordPress Address (URL)" setting and the "Site Address (URL)" setting, which are found in WordPress's backend under "Settings" > "General".

Right after you click "Save" you are logged out (because your session is bound to the domain) and sometimes it is tricky or even impossible to login again, for example if you entered an incorrect domain or something like that. Gladly there are two easy ways to change these crucial settings through either the functions.php (which can be found in your active theme's folder) or the wp-config.php (which can be found in the website's root)!

Method 1: wp-config.php

Add this to your wp-config.php:

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

Please note: as long as this entry exists in the wp-config.php the values can't be changed anymore via backend, this is like hardcoding the values.

Method 2: functions.php

Add this to your functions.php:

update_option('siteurl','http://example.com');
update_option('home','http://example.com');

Please note: it is important to remove this entry once you are back in backend and and the site is running normally again!

Et voilĂ : you should be able to log in again now. If not clear your browser's cache!

 

9Oct/150

Stop WordPress asking for FTP details when trying to install or update plugins

Depending on your server's settings and file permissions your WordPress system might not be allowed to update or install plugins by itself, causing it to ask for FTP access data whenever you try it. Manually entering those can be time consuming and annoying, luckily there is a better way!

You can actually define the FTP credentials permanently in the wp-config.php (found in the root of your WP install) and by doing so prevent WordPress from ever nagging you again. Just add this code to your wp-config.php:


/** Setup FTP Details **/
define("FTP_HOST", "localhost");
define("FTP_USER", "the-ftp-username");
define("FTP_PASS", "the-ftp-password");

Don't forget to replace the FTP_HOST, FTP_USER and FTP_PASS with the real access credentials.