This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
admin_memory_limit filter
This hook is handy for administrators who might need more memory for tasks such as updates. It’s important to note that memory limits for image processing (uploaded or edited by users of any role) are handled separately.
To use the admin_memory_limit filter, you first need to register it using add_filter. You can add this code to the functions.php file of your active theme or create a custom WordPress plugin.
At WePlugins, we always recommend creating a custom WordPress plugin when using hooks to avoid any issues when updating your WordPress theme in the future.
In the examples below, we define a function modify_admin_memory_limit_defaults which takes one parameter, and we register it using add_filter. The first parameter, admin_memory_limit, is the name of the hook. The second parameter, modify_admin_memory_limit_defaults, is the function to be called. The third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed to the registered function.
Sometimes, you may need to remove a registered hook, and you can use remove_filter to remove the admin_memory_limit filter.
Parameters
- $filtered_limit: (int|string) The maximum WordPress memory limit. Accepts an integer (bytes) or a shorthand string notation, such as ‘256M’.
Below is the parameter required to use this hook:
Live Example
Example 1: Basic Usage
Below is an example of how you can use this hook:
function weplugins_modify_admin_memory_limit_defaults($filtered_limit) { // Update the $filtered_limit variable according to your website requirements and return this variable. You can modify the $filtered_limit variable conditionally too if you want. return $filtered_limit; } // add the filter add_filter("admin_memory_limit", "weplugins_modify_admin_memory_limit_defaults", 10, 1);
Example 2: Conditional Memory Limit
Set a different memory limit based on certain conditions:
function weplugins_modify_admin_memory_limit_defaults($filtered_limit) { if (is_admin()) { $filtered_limit = '512M'; } return $filtered_limit; } // add the filter add_filter("admin_memory_limit", "weplugins_modify_admin_memory_limit_defaults", 10, 1);
Example 3: Remove Hook Callback
To remove a hook callback, use the example below:
remove_filter("admin_memory_limit", "weplugins_modify_admin_memory_limit_defaults", 10, 1);
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
Contact Us
If you’re having any trouble using this hook or need customization, please contact us and we’d be happy to assist you.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.