Troubleshooting errors is simpler when you have a method to detect these problems early. Wondering how to detect issues in your WordPress configuration quickly? Well, WP_DEBUG mode can help.
In this tutorial we are going to show you how to locate the WP_DEBUG in your WordPress site installation, how to edit and enable it with the local file editor and InstaWP.
Follow along as we guide you on how to enable it.
What is WP_DEBUG?
WP_Debug is a WordPress PHP constant that when enabled or set to true activates debugging and error reporting. The WP_Debug can be found in the wp-config.php file of your WordPress installation.
How WP_DEBUG Works
Errors and warnings in WordPress websites are common when you pick behind the scenes when developing or troubleshooting. Often, you would want to know why such errors and warnings occurred.
The WP_Debug provides ways for you to see these errors and warnings that might be hiding in the shadows of your website’s code. It’s a valuable tool that assists in troubleshooting and fixing issues.
Let’s consider a scenario for testing purposes and see how the WP_DEBUG helps you see issues and fix them.
We’ll use a plugin that is known to be buggy to demonstrate. There are a number of them but we’ll experiment with Health Check & Troubleshooting.
Let’s create a page or post that has a broken link.
- Navigate to the “Posts” or “Pages” section, depending on where you want to create the broken link.
- Click on “Add New” to create a new post or page.
- Give your post or page a title, such as “Broken Link ” your choice.
- Let’s go and create the broken link. Select a word or phrase in your content that you want to turn into a broken link. When you select the words or phrase, a toolbar box will pop up. Click on the chain-like icon in the toolbar.
- In the link dialog box that appears, enter a URL that does not exist or a non-existent page on your own website.
- Publish your post or page.
When you click on the link in the published page, you’ll most likely get a “404 Page Not Found.”
How To Enable The WP_Debug in WordPress?
Enabling the WP_Debug mode in WordPress means you know where to find this PHP constant.
Locate The WP_Debug In WordPress
If you don’t know where or how to find the WP_DEBUG in WordPress, follow these steps.
- In the WordPress installation file, navigate to your installation folder. You can get to your installation folder via FTP client, Cpanel, or your local machine if you are running WordPress through the local machine.
- Typically you will find 3 main folders and some other files. But let’s focus on the folder where you will find the file containing the WP_Debug PHP constant.
- Open the App folder, you will see only one folder named Public. Again open the folder called Public.
- In the Public folder, you will see a bunch of files and folders. In this tutorial, we are only concerned with one of those files. Look for the wp-config.php file. See this screenshot from a local file.
- In the wp-config.php file, you will see PHP constants for different functions. At the nearest end, you will find the PHP code that we want to change its constant.
Method 1: Enable WP_DEBUG Mode Using a Local File Editor
Note: This method is tricky, long, and suitable for those who understand WordPress well. Method 2 (check next section) is comparatively much easier to follow. 😉
There is a wide range of local file editors at your disposal for writing and editing code, each with its own unique features and capabilities. You have the opportunity to explore these local file editors extensively, allowing you to determine which one is most suitable for your specific use case.
Enabling the WP-DEBUG mode using a local file editor is a straightforward process but first, you need to be able to access WordPress installation from your computer. Below are simple steps on how to do that:
- Download your WP Installation file from your InstaWP dashboard. In the dashboard, select the 3 dots dropdown menu and you will see Export As > LocalWP. Click on LocalWP and your WordPress installation file will be downloaded to your computer. Open the file with any local file editor and start editing your WordPress site.
- Backup and Migration plugin can also give you the option to download your WordPress installation that you can have access to locally. In the process of backing up your WordPress, there are plugins that offer you the option to download your backup file to your computer. Some popular backup plugins include UpdraftPlus, BackupBuddy, and Duplicator. Check the documentation or settings of your chosen plugin to learn how to create a backup and download it to your local computer.
- Set up a local development environment: Start by setting up a local web server on your computer. You can use software like XAMPP (for Windows, macOS, and Linux), MAMP (for macOS), or WAMP (for Windows). These tools provide a web server (Apache), a database server (MySQL), and PHP, which are required for running WordPress.
- Some web hosting control panels, such as cPanel, provide functionality for creating backups of your website. You can access the control panel provided by your hosting provider and look for backup options. From there, you can generate a backup of your WordPress site and download it to your local computer.
Now that you are sure you have access to your WordPress installation, follow these steps to enable WP_DEBUG mode:
- Go to the directory/folder where your WordPress installation resides. Open the installation file with your preferred local file editor.
- Locate wp.config.php file (in the root folder). This file holds important configuration settings for your WordPress site.
- Now look for the line that says define(‘WP_DEBUG’, false);. By default, WP_DEBUG is set to “false” to disable debug mode.
- To enable WP-DEBUG mode, change false to true. The line should now read: define(‘WP_DEBUG’, true);.
- Finally, Save the changes to the wp-config.php file.
Method 2: How To Enable WP_DEBUG With The InstaWP File Editor?
To enable WP_DEBUG mode with InstaWP file editor you need to have an InstaWP account. To create an account go to https://app.instawp.io/onboard.
Let’s find the site we want to enable WP_DEBUG mode for in the dashboard.
- On the far right of that site, click on the 3 dots icon in the tool box. This will open a dropdown of additional tools for that site.
- Now find the feature that says “Tools”. Navigate to the tool option that says “Code Editor”.
- Click on “Code Editor” and the InstaWP custom file editor will be opened in a new tab.
- Find the “wp-config.php file.
- Open the file, scroll down a little and you will see the PHP constant that we want to edit.
- Change the false to true and save. Exit the file editor and you have successfully enabled WP_DEBUG mode with InstaWP file editor.
In addition, InstaWP provides a tool for you to view the error logs of your site.
To view the error log of your site, go to “Tools”, then click on “View Logs”. This pop image will show.
You will see the option to view 4 different logs which will enable you to troubleshoot and fix the errors.
How To Enable WP_DEBUG mode Using Configurations For New Sites?
By default, WP_DEBUG mode in the new WordPress installation is set to false. With InstaWP, you can enable WP_DEBUG mode for a completely new site with configuration. Let’s see what it looks like.
Open “Configuration” and you will see where to configure your new WordPress site.
Select “WordPress” and set default configuration for your site’s “wp-congig.php” file. Select the WP_DEBUG box.
Save your setting.
With this configuration, your site will have WP_DEBUG mode enabled from the start.
Conclusion
Navigating the world of WordPress can be an adventurous journey filled with opportunities and challenges. Whether it’s activating WP_Debug mode to uncover hidden errors and warnings or intentionally creating a broken link post or page, there are tools and techniques available to troubleshoot and enhance the WordPress experience. Among these tools, InstaWP stands tall and encompassing, a holistic companion for WordPress development.