Enable debugging and show php error messages on page in wordpress


While developing a wordpress website it is usefull to see (and understand) php error messages. If you are developing on a server and not localy these error-messages might be disabled.

For a live-website php error messages should always disabled as the could give hints about weakspots of your website to hackers.

This code-snippet turns on php erros just for logged in administrators and is a great compromise for everybody developing directly on a server. Of course this should be commented out as soon as the website is finished.


if ( current_user_can( 'administrator' ) ) {
     define('WP_DEBUG', true);
     define('WP_DEBUG_DISPLAY', true);     
     @ini_set('display_errors', 1); 
  • The if-clause makes sure these rules are only applied for logged in administrators.
  • The second line will enable wordpress debug mode. This should be set to false in your wp-config.php for live-pages
  • The third line enables the display of error-messages directly on the page.
  • The fourth line will configure the server to throw errors. This configuration will only be valid for the execution of the current php script.

If you want to read more about configuring wordpress to show errors you can read this text on wordpress.org.

Instead of displaying the php errors on your page, you could write them to a log file:

if ( current_user_can( 'administrator' ) ) {
     define('WP_DEBUG', true);
     define( 'WP_DEBUG_LOG', true );    
     @ini_set('display_errors', 1); 

If you need help setting up the debugging of your site comment this article.


Please enter your comment!
Please enter your name here