Puddinq.com sharing knowledge

Debug WordPress live

Debug WordPress live

If you want to know about errors on a production site your could set WP_DEBUG to true. But visitors will be able to see the errors and as a result trust in your site declines, to debug WordPress live it is best to log.

Log errors to a file on live-site

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false );

By logging the errors you can view the errors that happened when you were not looking.

To see errors you can set the above in wp-config.php, WordPress will then log all errors to a file called debug.log in your wp-content folder. And only you will be able to see them.

Show errors only to you

define('WP_DEBUG', $_GET['debug']);

By replacing the true / false with $_GET[‘debug’] you can see debug info if you add ?debug=true to the url.

  • normal users will not see bugs: https://www.example.com
  • but you could http://www.example.com/?debug=true

Using plugins

There are a number of plugins associated with debugging WordPress, these are some of the essentials

  • Query Monitor
    Brilliant in informing you information on the current query and alle errors / problems with it.
  • What the file
    This plugin does not show errors, but reveals what files / templates are used to construct the current page. This can help you to find in which files things go wrong
  • Simply show hooks
    Simply show hooks does not show errors, but displays where action hooks are used and which functions are hooked into them and into the filter hooks.

Live monitoring with tail

If you have shell access to your server you could run the following command:

watch -n 2 tail -n 20 debug.log

If you run this from the wp-content folder it will show you the last 20 lines every 2 seconds from the debug.log. This way you could monitor the websites behavior live while people visit.

More on the tail command: read here
More on debuggnig your own code: Link