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 static.domain.com, 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.

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”, “www.domain.com”);
    define(“WP_CONTENT_URL”, “http://static.domain.com”);

    1. above is example you need to replace values of domain.com and static.domain.com

      static.domain.com 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
    define(“WP_CONTENT_URL”,
    “http://static.domain.com”);
    in wp_config.php, it breaks my sites css.

    1. Ghulam Yasin, Yes once you add define(“WP_CONTENT_URL”,”http://static.domain.com”);, 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 static.domain.com?

        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,
    LeChat

  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?

    Thanks!

  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.

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

Most Popular Posts

Post via e-mail in WordPress

Posted on 12 years ago

Bhumi

How to use Pagination in CodeIgniter

Posted on 11 years ago

Bhumi

The Readers’ Poll – July 2013

Posted on 10 years ago

Bhumi