Back to Top

How to create Cookie Free domain in WordPress?

cookie free domain

Nowadays,optimization of site is most important and it’s good idea to use cookie free domains for static content in WordPress.Static contents are like images, JavaScripts and CSS.

Cookie Free domain is the separate domain which will not serve cookie and speed up your website.You can create sub domain for serving a static content so when browser load content from separate cookie free domain will not send cookie data.

To Setup a Cookie Free Domain

Let’s understand cookie free domain concept. It’s very easy to setup in WordPress.First of all, create a cookie free sub domain. By default, top-level domain cookie will be included into subdomain requests also.

In wordpress, You can define that to serve cookie for domain or not so once you setup, cookie will not get shared on subdomain.

Make sure that you have used “bloginfo(‘template_directory’)” to load your static content in theme files.

Let’s checkout the steps to set up cookie free domain in wordpress:

After creating a subdomain like, point out the domain to the wp-content directory of wordpress.

Now, Open your wp-config.php file of wordpress and add the following line of code into it.

define("COOKIE_DOMAIN", "");
define("WP_CONTENT_URL", ""); 

That’s it. Now load your site in browser ,you can see that the perfomance of website is increase and loading content faster.

Further Reading:

To Configure Auto Updates in WordPress
Pagination when getting posts from category in WordPress
To Exclude Latest Post from the WordPress Loop

Hope this article helpful to someone.As always, thanks for reading an article. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.And if any query,write to me on comment section.I would like to answer your query.

Comments (12)

  1. not work for me.

    I added
    define(“COOKIE_DOMAIN”, “”);
    define(“WP_CONTENT_URL”, “”);

    1. above is example you need to replace values of and is a sub domain created and content is uploaded to this subdomain

      better use w3 total catche plugin it has setting in cdn section

  2. Hi
    How to use “bloginfo(‘template_directory’)” to load static content in theme files.?
    Because as i put
    in wp_config.php, it breaks my sites css.

    1. Ghulam Yasin, Yes once you add define(“WP_CONTENT_URL”,””);, wordpress will look for content using this url and if wp-content directory is not pointing to this subdomain, site will looks like broken.

      I suggest first check once from cpanel that your wp-content is pointed to subdomain.

      If still you get any issue,let me know.

      1. Hi Bhumi, I tried your recommendation but it didn’t work for me. It broke my css too.

        Will I simply copy paste my wp-content and wp-includes onto

        And add the define code to wp-config? Won’t I need to rename my public_html directory for the static content to make this work?

  3. Hello Bhumi,
    I understand your article is geared towards WP pro-website. Would you by any chance know whether WP sets cookies automatically in the free version of their websites, which would therefore render the cookie consent message necessary?
    Many thanks,

  4. i also tried this method now. but all css is broken.
    i just create sub-domain and point the sub-domain to the wp-content of the site, but all broken.

  5. Hi.

    I want to make sure that there are “bloginfo ( ‘template_directory’)”
    How do I check it?, Where it should be listed?


  6. Greetings,

    First of all, thanks a lot for this tutorial.
    I would like more detailed instructions about these details that are in the comments session.
    Would you mind giving us a checklist, things that we need to pay attention?

  7. Hi Bhumi!
    Can I point to my root directory? (instead of wp-content directory of wordpress).
    That´s because I have some files in others folders.

  8. thanks a lot for this tutorial.
    its working but when use this code in wp-config file then image not show and design also change

  9. thanks you very much , this article helping me

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

MySQL coalesce() function

Posted on 7 years ago


How to define PHP Magic constants

Posted on 7 years ago


Learn about Variables in LESS CSS

Posted on 4 years ago


How to use Session in Joomla

Posted on 7 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago