Would you like visitors to keep getting your host’s cached pages after they answer your cookie banner?
In this guide, we’ll show you how to give WPConsent’s cookies new names with a short code snippet.
All you need is WPConsent and a way to add custom code to your site, such as our code snippets plugin, WPCode.
Table of contents
- Why Rename WPConsent’s Cookies?
- Choosing New Cookie Names
- Adding the Code Snippet
- Clearing Your Page Cache
- Checking the New Cookie Name
- Frequently Asked Questions
Before you get started, make sure WPConsent is installed and activated on your WordPress site.
Note: Renaming the cookies needs WPConsent 1.2.2 or later. This guide is for site owners who are comfortable adding custom code.
Why Rename WPConsent’s Cookies?
WPConsent saves each visitor’s choice in a cookie on your site. By default, its cookies are named wpconsent_preferences, wpconsent_geolocation, and wpconsent_tcstring.
Some hosts treat any cookie that starts with “wp” as a sign that the visitor is logged in. Their page cache then serves that visitor a fresh copy of every page instead of the cached one. Once a visitor answers your banner, they stop getting the faster cached pages.
Giving WPConsent’s cookies names that don’t start with “wp” lets those visitors keep getting cached pages. If your host’s page cache doesn’t work this way, you don’t need to change anything.
Choosing New Cookie Names
Each WPConsent cookie has its own filter, which is a hook that custom code uses to change a value. You only need to rename the cookies your site uses.
wpconsent_cookie_namerenameswpconsent_preferences, which stores each visitor’s consent choices. Every site uses this one.wpconsent_geolocation_cookie_namerenameswpconsent_geolocation, which remembers a visitor’s location when you use geolocation rules.wpconsent_tcstring_cookie_namerenameswpconsent_tcstring, which stores the consent string when IAB TCF support is turned on.
A good choice is a short prefix based on your site’s name. In our example, we’ll use sandys_consent, sandys_geolocation, and sandys_tcstring.
New names can only use letters, numbers, hyphens, and underscores. WPConsent removes any other characters.
WPConsent keeps a cookie’s default name instead of your new one in these cases:
- Nothing is left of the name once other characters are removed.
- The name starts with
__Host-or__Secure-. Browsers save cookies with those names only when they are secure cookies, and WPConsent’s cookies are not. - The name is the same as another WPConsent cookie’s name, or a name one of them used before. Two cookies with one name overwrite each other.
Note: If you use Shared Consent across subdomains, give the cookies the same names on every site. The banner on each site reads one shared cookie.
Adding the Code Snippet
The filters go in a short PHP code snippet. The code below renames all three cookies.
Before you add it, replace the sandys_ names with your own. If you’re keeping a cookie’s default name, leave out its filter.
add_filter( 'wpconsent_cookie_name', function () {
return 'sandys_consent';
} );
add_filter( 'wpconsent_geolocation_cookie_name', function () {
return 'sandys_geolocation';
} );
add_filter( 'wpconsent_tcstring_cookie_name', function () {
return 'sandys_tcstring';
} );
We recommend adding it with WPCode as a new PHP snippet.
If you haven’t added a snippet before, see our guide on creating your first snippet in WPCode.
In WPCode, give the snippet a title you’ll recognize, such as Rename WPConsent Cookies. Then, paste the code into the Code Preview box with the Code Type set to PHP Snippet.

In the Insertion section, leave the Insert Method on Auto Insert and set the Location to Run Everywhere.

Run Everywhere loads the snippet early enough for WPConsent to use the new names on every page, in the admin, and in background requests. A location such as Frontend Only doesn’t run in the admin or in many background requests. Those requests keep the old names.
Finally, switch the snippet’s status to Active. Then, click Update to save it. On a snippet you haven’t saved yet, this button reads Save Snippet.

If you add the code another way, such as in a site-specific plugin, add the filters on every request, before WordPress’s init hook runs.
Clearing Your Page Cache
Once the snippet is active, clear your page cache in your caching plugin or your host’s control panel.
See How to Clear Your Cache in WordPress for a step-by-step guide.
Pages cached before the change still use the old cookie names. A returning visitor who lands on one of those pages sees the banner again.
After you clear the cache, every page uses the new names. On a visitor’s next page view, WPConsent copies their saved choice to the new cookie and removes the old one. Visitors keep their choices and don’t need to answer the banner again.
Checking the New Cookie Name
Once the new names are in place, WPConsent updates its own entry for the consent cookie in your cookie list. That way, your preferences panel and cookie policy page show the cookie under its new name.
The entry is updated the next time anyone loads a page on the front end of your site. To check it, visit your site once. Then, go to WPConsent » Settings. From the top of the page, select the Cookies tab.

In the Essential category, the Cookie Preferences row now shows your new name in the Cookie ID column.

That’s it! WPConsent’s cookies now have names that work with your host’s page cache. Next, take a look at our guide on database and cache management. It shows how to clear WPConsent’s cookies cache and keep your stored records tidy.
Frequently Asked Questions
Below, we’ve answered some of the most common questions about renaming WPConsent’s cookies.
Will my visitors have to give consent again?
No. WPConsent moves each visitor’s saved choice from the old cookie to the new one on their next page view. The only exception is a page your cache stored before the change, which is why it’s important to clear your page cache.
How do I go back to the default names?
Deactivate or delete the snippet. Then, clear your page cache. WPConsent goes back to its default names and moves visitors’ choices back to them in the same way.
Does renaming the cookies affect my Google Tag Manager template?
The WPConsent Google Tag Manager template reads visitors’ choices from the data layer and from WPConsent directly. It also checks the wpconsent_preferences cookie as a fallback. With a renamed cookie, it relies on the data layer and WPConsent’s live updates instead.
Can I rename the cookies from the WPConsent settings?
The cookie names are set with code, using the filters in this guide. That keeps the names the same on every page and request, which the banner needs to read visitors’ choices.