Skip to content

How to Debug in WordPress

  • QA

When things go wrong, it’s usually due to PHP or JavaScript issues, or a clash between your site’s theme and plugins. Furthermore, there could be caching issues preventing your site from displaying as expected or a function not working properly.

Follow the steps below to troubleshoot the problem on the WordPress site.

Determine Whether It Is a Caching Issue

Simply open your browser’s console and examine the request header to see if your site is cached.

Another approach is to view the page’s source code.

Determine Whether It Is a JavaScript Error

Most JavaScript errors will be shown in the browser’s console. Simply enable it and find the file coming with the issue. You might need to contact the plugin or theme’s author for further assistance.

Determine Whether It Is a PHP Error

PHP error will display in the debug.log file when you enable debug log mode in WordPress.

To do so, add the following code snippet to your wp-config.php file.

The debug.log file is located under wp-content/uploads directory by default. If it doesn’t exsit, simply create a new one. Otherwise, you can change the file location using the code below:

In fact, I often use plugin to display the error right under the Dashboard. All you need to do is to install plugin and activate it, the plugin will guide you how to do it. Nothing to remember and easy to follow 😀

Determine Whether It Is a Conflict Issue

A theme or plugin conflict is the second most common cause of any WordPress problem.
This is the method that the author of the theme or plugin will recommend if you contact them.

Deactivate each plugin one by one or return to the default theme.

Actually, as a QA analyst and CS agent, it is my last choice.

It requires you to have a staging site so that you can make changes to the site without affecting the current users. Furthermore, maintaining a staging site necessitates time and effort.

That being said, it’s a quick and easy way to find a clue of what going wrong when none of the other methods are working.

Debugging Flow

  1. Turn on WP Debug log

Copy and paste the following constants to the wp-config.php file

define( ‘WP_DEBUG’, true );

define( ‘WP_DEBUG_LOG’, true );

Find log file under wp-content/debug.log or create a new one

  1. Install this plugin Query Monitor
  2. Clear browser cache
    1. Use Incognito mode
  3. Test conflict
    1. Deactivate all plugins
    2. Switch to other themes
    3. Switch to other sites
      1. Multisite / Single site
      2. Nginx / Apache
      3. Sub-directory / Sub-domain
    4. Downgrade plugin version
  4. Use browser developer tool
    1. Elements: check CSS 
    2. Console: check JS
    3. Network: check the HTTP request

Setup WordPress Environment for Testing

Leave a Reply

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