In case you will see a generic error message like shown below when opening a page or post in WordPress, in most cases this issue is related to PHP or a database corruption.

There has been a critical error on your website.


To see whats the reason for this issue you should enable debugging in WordPress by adding the following code at the bottom of the wp-config.php file.

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


Debugging is now enabled and errors will be written to the log file named debug.log located in the wp-content folder of your WordPress installation.


So in my case this issue is related to the memory limit in PHP. This issue was appearing for a really large post in draft mode which includes a lot of screenshots. So either I have to reduce the length and screenshots of this post or I have to increase the memory limit in PHP.

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 790528 bytes) in /var/www/blog/html/wp-includes/class-wpdb.php on line 2315
There has been a critical error on this website. Please check your site admin email inbox for instructions.


Source: https://kinsta.com/knowledgebase/there-has-been-a-critical-error-on-your-website/



Increase PHP Memory Limit

Increasing the PHP memory limit is the easiest way to fix this memory error shown above. You can do this by adding the following code to your wp-config.php file:

define('WP_MEMORY_LIMIT', '512M');


Make sure to add the WP_MEMORY_LIMIT constant before this block of code:

!! Note !! If you add the WP_MEMORY_LIMIT value at the end of the wp-config.php and not before this block, the modification will not have any effect!

/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');


Source: https://wp-staging.com/docs/php-fatal-error-allowed-memory-size-of-134217728-bytes-exhausted





Links

Fix WordPress Memory Limit & “Allowed Memory Size Exhausted”
https://wp-staging.com/docs/php-fatal-error-allowed-memory-size-of-134217728-bytes-exhausted

How to fix the “There has been a critical error on your website” error
https://kinsta.com/knowledgebase/there-has-been-a-critical-error-on-your-website/