Search code examples
phpwordpresswordpress-rest-api

How to disable error message in REST API output


Recently I have upgraded WordPress theme and plugins of my website to enable REST API. My site has more the 30 thousand custom post types currently with few meta information. When I try to access https://example.com/wp-json/wp/v2/book It gives me a fatal error about allowed memory size which has full file name with the full path of my hosting server.

I want to disable the error message or replace the error message with something else so that file path does not display. How to do it?

FYI, I have used the following constant in the wp-config.php file to solve this issue but no luck.

define('WP_DEBUG', false);
define('WP_MEMORY_LIMIT', '256M');

Shows the error with file path in hosting server while request REST API


Solution

  • Found a solution at wpmudev to hide the error message displaying in the REST API output:

    After the line define('WP_DEBUG', true); add the line:

    @ini_set('display_errors', 1);