Some common debug skills in WordPress development

Source: Internet
Author: User
This article mainly introduces some common debugging skills in WordPress development. For more information about debugging code, see debugging code, master some WordPress debugging skills to perform better debugging. For example, in a local development environment, you may need to output all the code warnings to facilitate improper code modification.

This article describes all the debugging methods of WordPress. if you are a developer, you must master these skills to greatly improve efficiency.

Enabling debug mode requires some constants to be added to the wp-config.php file in the root directory, so all the code described below is added to the wp-config.php file in the root directory.

WP_DEBUG

WP_DEBUG is a constant of WordPress. after setting it to True, WordPress enters the developer mode and outputs all development prompts to the screen.

I strongly recommend that you enable WP_DEBUG in the local development environment to facilitate development.

// Enable the developer mode define ('WP _ debug', true );

WP_DEBUG_LOG

If you want to record all the errors that occur during WordPress running, you can enable WP_DEBUG_LOG. after it is enabled, all errors will be recorded and stored in the wp-content/debug. log file.

To record errors, you must enable the WP_DEBUG mode. only when WP_DEBUG is enabled can errors be generated.

// Enable the error record define ('WP _ DEBUG_LOG ', true );

WP_DEBUG_DISPLAY

You can enable WP_DEBUG_DISPLAY when enabling WP_DEBUG_LOG and WP_DEBUG if you want to record WP_DEBUG errors only through WP_DEBUG_LOG but not display them on the screen.

// Prevent the error from being displayed on the screen. define ('WP _ debug_display', true); SCRIPT_DEBUG

By default, the WordPress background uses compressed and merged JS and CSS files.

Sometimes we may not want the background to use compressed CSS and JS files for debugging. in this case, we can set SCRIPT_DEBUG to True.

// Disable the compressed CSS and JS file define ('script _ debug', true );

SAVEQUERIES

If you want to optimize the number of database queries, SAVEQUERIES is a very important thing. if you set SAVEQUERIES to True, WordPress records the SQL statements and time spent in each database query.

// Record the database query define ('saverrors', true );

After logging is enabled, you can use the queries variable of $ wpdb to retrieve all data queries. put the following code in the topic's footer. php file to view all database queries.

<?php var_dump( $GLOBALS['wpdb']->queries ); ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.