+4 votes
in Webmasters by (1.5m points)

How to change the URL of a WordPress blog

1 Answer

+5 votes
by (725k points)
Best answer

Something that sooner or later we will find the webmasters that work with WordPress is the need to change the URL of a WordPress blog . This need may arise, for example, from a domain change or if we want to remove / add the three www at the beginning of our URL.


There are several methods to change the WordPress URL, but it will be the object of the article to explain one of the methods, which will require access by ftp or similar to the functions.php file of the WordPress theme or template that is active in our blog.

How to change the URL of a WordPress blog

The way that most of you will know is to go to the Ajustes → Generales menu Ajustes → Generales of the WordPress control panel and among the available options we have the following:

  • WordPress address (URL) : to indicate the blog URL
  • Site address (URL) : to indicate the URL of our page if it is different from that of the blog. For example we can have our page in the URL http://www.miweb.com and the WordPress blog we can have it in the URL http://www.miweb.com/blog


But the above may not be enough, for example when we change the domain of a blog and when changing the URL of the blog we lose access to the administrator panel, in this case we have several options, all documented at http://codex.wordpress.org/ Changing_The_Site_URL , but in this article I will only explain what in my opinion is the best way to do it. The different ways to change the WordPress URL are:

  • Editing the wp-config.php file (method not recommended).
  • Editing the functions.php file of our theme or template (recommended method and will be the one I will explain).
  • Editing the URL directly in the database with phpMyAdmin or similar.

Change the WordPress URL by editing the functions.php file

To change the WordPress URL by editing the functions.php file of our theme, we simply have to add the following lines to the file at the beginning, just after opening the php tag:


Once the file is edited, we access our blog to the login page for example http://miweb.com/wp-login.php , to ensure we access the login page a couple of times and the WordPress URL is already changed . Now we can remove the lines that we added before to the functios.php file. It is very important to remember to eliminate these lines.

There may be strange situations in which our theme does not have a functions.php file, so we will have to create one with the following content:

<?php update_option('siteurl','http://miweb.com');
update_option('home','http://miweb.com'); ?>

Once created, we proceed in the same way as described above.

As you can see it is a simple method, it has always worked for me. The method of directly editing the WordPress URL in the database does not explain it because editing the database directly always poses a risk and doing so through the functions.php file seems to me to be a simpler method for the vast majority of users, have or not knowledge of WordPress.

Once we have changed the URL of our blog, it is advisable to rebuild the .htaccess file from the Ajustes → Enlaces Permanentes → Guardar Cambios panel Ajustes → Enlaces Permanentes → Guardar Cambios .

Most popular questions within the last 20 days