Skip to content

Instantly share code, notes, and snippets.

@ideadude
Created March 24, 2025 14:22
Show Gist options
  • Save ideadude/9e80ca6b6bf4c4264afd58ce5a7453e0 to your computer and use it in GitHub Desktop.
Save ideadude/9e80ca6b6bf4c4264afd58ce5a7453e0 to your computer and use it in GitHub Desktop.
Increase memory and execution time for WP admins and crons.
<?php
/**
* Increase memory and execution time for WP admins and crons
* Add this code into a custom plugin or code snippet.
*/
function my_init_memory() {
if( current_user_can( 'manage_options' ) ) {
ini_set( 'max_execution_time', 300 ); //300 seconds = 5 minutes
ini_set( 'memory_limit', '812M' );
} elseif ( wp_doing_cron() ) {
ini_set( 'max_execution_time', 300 ); //300 seconds = 5 minutes
ini_set( 'memory_limit', '300M' );
}
}
add_action( 'init', 'my_init_memory', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment