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 (16)

  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. Hi and thanks for your article. just still don’t understand how can this can work for content that already exist and that is hosted in root/wp-content/… have i also to manually move all static files to folders (to be created) inside subdomain static.domain.com? i followed every step and after flushing every possible cache yslow doesn’t show any change 0%…it seems content is still taken from same folders in root… 🙂

  9. 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

  10. thanks you very much , this article helping me

  11. LARRY SPENCER says:

    The sample code that you provided does not work, even after replacing the values. I wish the article was a little more precise.

  12. If some one needs expert view concerning blogging after that
    i recommend him/her to go to see this blog, Keep up the nice work.

  13. kartubagus7.wordpress.com says:

    I got this web site from my friend who shared with me regarding this web
    site and at the moment this time I am browsing this website and reading very informative content at this place.

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

Type Hinting Callable Functions in PHP

Posted on 7 years ago

Bhumi

MySQL coalesce() function

Posted on 12 years ago

Bhumi

What are Traits in PHP

Posted on 9 years ago

Bhumi