How to fix the error “Cookies are blocked or unexpectedly exported” – Learn WordPress from a to z

Tutorials 0 lượt xem

Errors encountered are often part of the development process. During that time, you will see an error message, “Cookie blocked or unexpected output. You must enable cookies to use WordPress. “

This error can occur when you try to login to your WordPress site. This article explains some options to resolve the “cookie enabled” error.

cookies blocked or unexpected output

Contrary to what the error message indicates, this message does not necessarily mean that it appeared because the cookie was blocked. You will often get that error due to the involvement of a security plugin or cache on your site or a change of server/IP address after moving your site to another host.

Sometimes this error goes away just by refreshing the browser. Do the fixes below if the error does not go away.

There are only a few possible reasons why your WordPress site is getting a cookie error when you try to login to your site. Below you find the two most common reasons. Fortunately, you can fix them quickly.

WordPress Login Error Caused by Security Plugin or Memory

Security or cache plugins can interfere with your WordPress site’s login and cookie handling and prevent WordPress user login cookies from being generated correctly. This can result in the error “Cookie blocked or unexpected output. You must enable cookies to use WordPress. To fix that, temporarily deactivate the security and cache plugin by renaming the plugin’s folder.

Cookies refused

To do so, log into your site via FTP or a file manager plugin. Then rename the specific folder /wp-content/plugins/plugin-name to something else.

Try logging into the WordPress dashboard again. If this has fixed your problem, reinstall the cache and security plugin. Also let the developers of these plugins know about your cookie problem so they can fix it.

If you move your WordPress site to another server while the domain is still there and unchanged, it could create a conflict between the cookie stored in your browser and the new host. So delete all existing browser cookies and try to login to WordPress dashboard.

You can access the wp-config.php file in the root directory of your site. Then paste the code below at the end before the comment “/* That’s all, stop editing!…*/.”.

define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST'] );

Refresh your browser and re-login to your site.

If the solution above doesn’t work, try the troubleshooting below. I’ve broken this solution down into three separate steps:

Step 1: Open and edit the functions.php . file

You can access and open this file using the cPanel file manager or through an FTP tool. Once logged in, go to your site’s theme directory where the functions.php file is located . The location of this file is usually wp-content/themes/theme-name/functions.php

Step 2: Add the code to the functions.php . file

Copy below code and paste at the end of file functions.php

if ( SITECOOKIEPATH != COOKIEPATH ) {
setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
}
<div>
<span>1</span><span>2</span><span>3</span>
</div>

Step 3: Save the file

After saving and uploading the modified functions.php file to your site, you should no longer see the error.

Epilogue

With the above instructions, I hope you will fix the error as soon as possible.

If you find it interesting, you can follow the  WordPress basics section  to know more new knowledge.

Follow fanpage to receive the latest posts:  Group

Bài viết liên quan