Understanding WordPress GUIDs: What They Are, and Why Change Them

#
By Brad Touesnard, Founder & CEO

The WordPress GUID is a unique identifier for individual posts, pages, media, and practically any other custom post type. As such, it’s a key element in rendering your WordPress content and powering the WordPress RSS feeds which allow you to syndicate that content.

In this post, we’re going to discuss what a WordPress GUID is, why it’s important for your WordPress site, and why you might want to change one.

What Is a GUID?

A Globally Unique Identifier (GUID) is defined as “a 128-bit label that is used to create a unique identifier for system resources.” For example, ASP.NET and Microsoft SQL Server use GUIDs that look like this:

6F9619FF-8B86-D011-B42D-00C04FC964FF

Using a GUID as a unique identifier is a concept that existed well before WordPress. They’re used in all kinds of applications. Languages such as C++, C#, and Java often generate GUIDs for database keys.

GUID is not a universal acronym used in all software systems. Those working with Microsoft technologies will generally use GUID, while others might use the term Universally Unique Identifier (UUID). While the name to describe it might be different, the premise is the same.

Using a GUID as a unique identifier for data is slightly different from using the ID fields in your WordPress MySQL database. The ID fields use incremental integers to identify the various data types on your site, wp_posts vs. wp_comments, for example. This means that a post could have the same ID value as a comment. Fortunately, WordPress typically only queries specific data types at any given time, so the ID only needs to be unique for the data type being retrieved.

So why does WordPress use GUIDs?

How WordPress Uses GUIDs

Every record in the WordPress wp_posts table has a unique GUID value as well as an ID value. The most common place the GUID is used is in the WordPress RSS feed. Since the RSS 2.0 specification was published in 2002, RSS feeds have implemented the guid element as a unique identifier for any feed item.

If you take a look at the RSS feed of this blog you will see each item element contains a guid element, which has a string value similar to this:

https://deliciousbrains.com/?p=92491

This is the format WordPress uses for each post type’s GUID, a URL format made up of the domain followed by a query string in the following structure:

?p=[ID]

In this case, the ID value matches the ID value of the wp_posts record in the database.

You might wonder why the GUID is made up of these parts, the site URL and the query string with the post ID. The hint is in the name; “Globally Unique Identifier.” No other site on the internet will have the same site URL, so combining the site URL and the post ID in this way ensures that the GUID is unique across the entire internet, not just on the site the post belongs to.

While the post’s GUID is a unique identifier, it’s also a valid, working URL. In fact, if you go to the URL in the example above, it will redirect you to the blog post it belongs to – Why You Should Use the WordPress HTTP functions to Make API Requests. Those of us who used or built websites before the introduction of so-called “pretty URLs” will remember that this is how most URLs on the web looked. This is also the URL the post has when the WordPress Permalink Settings are set to “Plain”:

The WordPress Permalinks screen.

However, even if you change your “Permalink Settings” to anything other than “Plain”, the GUID for the post type remains and is always a unique identifier for that piece of content.

How an RSS Feed Uses a WordPress GUID

RSS feed readers such as Feedly use the guid element to uniquely identify an item in the feed. The feed reader will use the GUID to determine if an item is new (and whether to display it).

For example, if an item in the RSS feed item’s link element were used as the unique identifier, and you were to update the “pretty” URL of a post from…

https://deliciousbrains.com/tour-of-the-wordpress-database/

to…

https://deliciousbrains.com/tour-wordpress-database/

then the link element would also be updated. This means the feed reader would see the updated URL as a new post, and show a duplicate item. However, the GUID of the post stays the same. The RSS reader uses this element to understand that the post is the same, and won’t add it again.

Similarly, podcast syndication relies heavily on RSS feeds. You’ll find that all the major podcasting networks – Apple Podcasts, Google Podcasts, Amazon Music, Spotify, and more – will use the GUID of the episode to identify items in the feed. As with RSS feed readers, it would wreak havoc with your show if the podcast networks used the link and not the guid field in the feed to uniquely identify episodes. You could end up with all sorts of issues, including duplicate podcast episodes, incorrect content for existing episodes, and even missing episodes.

Why You Might Change a WordPress GUID

There are very few reasons you should ever change a WordPress GUID. In fact, we can only think of one situation where you should do so. We’ll cover that in the next section. First, let’s look at how you might accidentally change your GUIDs and what happens if you do.

For example, say you’re moving a site from one domain to another and need to change your URLs. It may seem straightforward to export the database and replace all of the old URLs with the new ones. Remember, though, WordPress uses URLs as GUIDs. Changing the URL of your posts will change the GUIDs as well. That can lead to the problems we outlined above, where RSS readers will display old content as new.

This is part of what makes a manual site migration so painful. A solution like WP Migrate DB Pro takes care of all the heavy lifting involved in a site migration, including an option to automatically update GUIDs or leave them as they are.

The Exception to the Rule

There is one instance where it might be beneficial to change your GUIDs: when migrating from a development or staging site to a live server.

If this is the first time the WordPress site goes live, you don’t want your GUIDs to be URLs related to your development environments. Your web host might use a randomly generated subdomain on a separate domain for your staging sites, and you’ll have a bunch of GUIDs with a domain like cO9fb8aa5e.whcli.net in your database. While it won’t be a disaster to leave them as is, it isn’t reassuring to see these URLs in a live database.

In both the free and Pro versions of WP Migrate DB, you have the option to replace GUIDs:

The WP Migrate DB interface.

The “Replace GUIDs” option is checked by default. If you’re migrating a site that’s already live, you should uncheck this option.

Conclusion

GUIDs are one of the few things that should remain unchanged in a live WordPress site. The GUID is the unique identifier of a post, page, podcast, or any other post type. You can change the URLs and alter the post content, but the GUID should almost always be left alone. If you absolutely must change your GUIDs, we recommend using a plugin instead of trying to alter them manually.

If you choose to update elements of the GUID (such as the full URL), a plugin such as WP Migrate DB is a convenient and safe way to do so. It lets you run a find and replace on your database with the option to replace GUIDs or not, depending on your situation.

Do you ever change a WordPress GUID, and if so, is WP Migrate DB a tool you use? Let us know in the comments section below!

About the Author

Brad Touesnard Founder & CEO

As founder of Delicious Brains Inc, Brad has worn many hats. He now spends most of his time managing the product teams and growing the business. Before starting this company, Brad was a freelance web developer, specializing in front-end development.