Error Solutions

Increasing WordPress Memory Limit: The Magic Line of Code to Add to wp-config.php

  • 17 min read
  • Hostragons Team
Increasing WordPress Memory Limit: The Magic Line of Code to Add to wp-config.php

To increase the WordPress memory limit, adding the line define('WP_MEMORY_LIMIT', '256M'); to the wp-config.php file is sufficient for most websites. This code raises the amount of PHP memory that WordPress can use for plugins, themes, media processing, and the admin panel. The line of code should be placed just before the comment line /* That's all, stop editing! Happy publishing. */ in the wp-config.php file. If your hosting account has a lower PHP memory limit, this setting alone may not be enough; in this case, the limit should be increased either through PHP settings or the hosting panel.

Many issues on WordPress sites, such as "Allowed memory size exhausted," white screens, failure to access the admin panel, WooCommerce product import errors, Elementor editor not loading, or backup plugins failing, stem from insufficient memory. In this guide, you will learn step-by-step how to add the correct line of code to wp-config.php, where to place it, what value to choose, how to check if the change worked, and the limits on the hosting side.

What is WordPress Memory Limit?

The WordPress memory limit is the maximum amount of PHP memory that WordPress is allowed to use during a process. For example, when creating a page, theme files are executed, plugins are loaded, content is fetched from the database, shortcodes are processed, and images may be resized if necessary. All these processes consume a certain amount of RAM on the server. The memory limit is the upper boundary drawn for this consumption.

The default WordPress memory limit can be 40M or 64M in most installations. However, for modern WordPress sites, this value often remains low. Especially when using WooCommerce, multilingual setups, page builders, security plugins, SEO tools, backup plugins, and advanced theme panels, 128M or even 256M is a more realistic starting point.

It is important to distinguish between the WordPress memory limit and the total RAM capacity of your hosting account. The WordPress memory limit is a software limit granted to PHP processes. The resources of your hosting package cover broader server limits, such as CPU, RAM, I/O, inodes, and concurrent processes. For a more stable WordPress performance, your hosting infrastructure should also be suitable for your site's load. You can check the WordPress hosting packages page for more on this topic.

The Magic Line of Code to Add to wp-config.php

The most commonly used and practical method to increase the WordPress memory limit is to add the following line to the wp-config.php file located in the main directory of your site:

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

This line sets the memory that WordPress can use during its normal operation to 256 MB. For many corporate websites, blogs, portfolio sites, and medium-sized WooCommerce stores, 256M is a balanced value. For very small blogs, 128M might be sufficient; whereas, for intensive e-commerce, LMS, membership systems, or setups using many plugins, 512M may be necessary.

Additionally, the following line can be used for admin panel operations:

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

This second line specifically sets the upper limit for heavier operations running in the WordPress admin panel. For example, theme customization, large product imports, image optimization, bulk post editing, or database migration processes may require more memory on the admin side. A practical configuration might look like this:

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

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

Setting these values too high randomly does not always mean better performance. Increasing the limit does not mean using memory efficiently; it simply gives WordPress more room to work. If a plugin is causing a memory leak, raising the limit may only temporarily mask the issue. Therefore, alongside increasing memory, checks should also be made on plugins, themes, and PHP versions.

Where to Place the Code in wp-config.php?

Placing the code in the correct location is critical. In the wp-config.php file, you will find a line similar to the following:

/* That's all, stop editing! Happy publishing. */

You should add the memory limit code above this line. An example of correct usage is as follows:

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

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

/* That's all, stop editing! Happy publishing. */

The reason for this placement recommendation is that WordPress reads the configuration constants before loading core files. If the code is added to the bottom of the file, especially after this comment line, it may not work as expected in some installations. Additionally, adding the code after the PHP closing tag can lead to syntax errors and prevent the site from opening.

Step-by-Step Guide to Increase WordPress Memory Limit

1. Backup Before You Begin

wp-config.php is one of the most critical files in WordPress. It contains the database name, username, password, table prefix, security keys, and error settings. Even a single wrong character can cause the site to temporarily stop working. Therefore, before making any changes, download a copy of the file to your computer or create a backup in your hosting panel.

For a safer approach, taking a full site backup is the best practice. Especially on live WooCommerce sites, a database backup should also be taken before the operation to avoid losing orders. You can use the WordPress backup guide content for backup instructions.

2. Open the wp-config.php File

The wp-config.php file is typically accessed via public_html, httpdocs, or your site's root directory. You can use one of the following methods to access it:

  • File Manager in the hosting control panel
  • FTP client
  • SFTP connection
  • Terminal editor via SSH
  • File editing tool in managed WordPress hosting panel

For beginners, the File Manager is the most practical option. However, you should use an editor that won’t corrupt the character encoding while editing the file. Instead of Windows Notepad, using VS Code, Sublime Text, or the internal code editor of your hosting panel is safer.

3. Add the Line of Code in the Correct Position

Find the line /* That's all, stop editing! Happy publishing. */ in the file. Add the following code just above this line:

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

If you are performing high-memory operations in the admin panel as well, you can add the following line just below it:

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

If there are any other lines in the file that already define the same constants, do not add them again. Defining the same constant twice can lead to PHP warnings or unexpected behavior. It is better to update the value in the existing line.

4. Save the File and Check the Site

After saving the file, test your site’s homepage, the admin panel, and the page where you encountered the error. For example, if Elementor isn’t loading, restart the editor; if the WooCommerce import is interrupted, try the same import process again in a controlled manner. If the site shows a white screen, check for any typos in the line you added.

Here are the key points to pay attention to in correct spelling:

  • The word define can be written in lowercase and will be recognized by PHP.
  • The constant name must be WP_MEMORY_LIMIT.
  • The value should be written in single quotes, like 256M.
  • The line must end with a semicolon.
  • The code must remain within the PHP block.

5. Verify That the Change Worked

There are several ways to understand if the limit has genuinely increased. The Site Health screen in the Tools section of the WordPress admin panel can provide hints about the PHP memory limit under server information. Some security and performance plugins also display the current memory limit value. Alternatively, you can check the memory_limit value from the PHP info screen in your hosting panel.

Remember: Writing 256M in wp-config.php does not always mean you can use 256M if the server-side PHP memory_limit is set to 128M. If the server's upper limit is lower, WordPress will be restricted to that upper limit. In such a case, you will need to change the PHP settings from the hosting panel or contact the support team. For Hostragons users, suitable package and resource options can be compared on the Hosting Packages page.

Which Memory Limit Value Should Be Selected?

The correct value varies depending on the site's structure, the number of plugins, traffic levels, and the operations being performed. The memory needs of a small blog are not the same as those of a WooCommerce store with thousands of products. Based on general experience, the practical table is as follows:

Which Memory Limit Value Should Be Selected?
Site TypeRecommended WP_MEMORY_LIMITRecommended WP_MAX_MEMORY_LIMITNote
Personal blog or simple corporate site128M256MTypically sufficient for low-plugin setups.
Corporate site using a page builder256M512MMore stable with Elementor, WPBakery, or similar tools.
WooCommerce store256M512MProducts, variations, and payment plugins increase memory usage.
Multilingual or membership system256M-512M512MMultiple queries and role checks create load.
Large portal with heavy plugins512M512M or higherHosting resources should be analyzed as well.

This table is a starting point; it is not a strict rule. If errors disappear after 256M and the site runs stably, there is no need for a higher value. However, if errors persist at 256M, it is necessary to examine memory-consuming plugins, PHP error logs, and database queries rather than just raising the limit.

What to Do If wp-config.php Is Not Enough?

In some cases, increasing the WordPress memory limit cannot be resolved with just wp-config.php. This is because the PHP memory_limit value may be set lower at the server level, or your hosting package may operate under certain resource limits. In such a case, you can consider the following alternatives.

Increasing memory_limit Value from PHP Settings

In many hosting panels, the memory_limit can be changed from the PHP settings section. Here, you may see options like 128M, 256M, or 512M. The server-side memory_limit value can be thought of as the upper limit that WordPress cannot exceed. Setting this value to 256M or 512M provides a more solid ground for the wp-config.php settings to work.

If your panel has a PHP selector or PHP settings section, check the values of max_execution_time, upload_max_filesize, and post_max_size in addition to memory_limit. Especially for large theme demo imports, backup restorations, and WooCommerce CSV imports, not only memory but also execution time and upload size are important.

Using .htaccess or php.ini

In some server configurations, the memory limit can be increased through the .htaccess or php.ini file. However, this method does not work in every hosting environment. Support may vary due to Apache, LiteSpeed, PHP-FPM, or different panel configurations. A wrong .htaccess rule can cause a 500 Internal Server Error, so for beginners, wp-config.php should be the first choice.

If php.ini can be used, an example value would be: memory_limit = 256M. However, this file must be in the correct directory, and the hosting must allow user-based PHP settings. If you are unsure, it is safer to consult your hosting support team.

Reviewing the Hosting Package

If a site consistently hits the memory limit, the problem may not be just a setting value. Traffic may have increased, the number of plugins may have risen, WooCommerce order volume may have grown, or the theme may be consuming more resources than necessary. Shared hosting may be sufficient for small and medium-sized sites; however, intensive WooCommerce stores, high-traffic news sites, or membership platforms may require more robust WordPress hosting, cloud servers, or VPS.

At this point, the goal is not to choose the most expensive package, but to determine the resources that truly fit the site's needs. CPU limits, RAM, NVMe disk, LiteSpeed cache, backup policies, and quality of technical support should be evaluated together. Depending on your needs, you can check the Corporate Hosting Solutions, VPS Server, or Domain Lookup pages.

Symptoms of Memory Limit Issues

A memory limit insufficiency does not always present itself with the same message. Sometimes you may receive a direct PHP error message, and other times the site simply shows a blank page. The most common symptoms include:

  • “Allowed memory size of bytes exhausted” error
  • WordPress white screen issue
  • Slow loading or failure to open the admin panel
  • Elementor or page builder freezing during loading
  • WooCommerce product import process being interrupted
  • Backup plugin stopping before completion
  • Image upload or thumbnail generation errors
  • Timeout during theme demo content import

One of these symptoms could be due to the memory limit; however, it is not the only possibility. Similar issues can also occur due to a faulty plugin, incompatible theme, outdated PHP version, database locking, or firewall rules. Therefore, checking the error logs after increasing the memory limit is the healthiest approach.

A Realistic Example: WooCommerce Product Import Error

A Realistic Example: WooCommerce Product Import Error

Let’s say you are bulk importing products via CSV for a WooCommerce store with 3,000 products. The site has SEO plugins, shipping integration, payment modules, security plugins, caching plugins, and image optimization tools. With the default 64M memory limit, the import stops after the 200th product, and the error logs show a memory exhaustion message.

In this case, the first step is to add define('WP_MEMORY_LIMIT', '256M'); and define('WP_MAX_MEMORY_LIMIT', '512M'); to the wp-config.php file. Then, the PHP memory_limit should be set to 512M in the panel. The import process is broken down into smaller chunks; for instance, instead of 3,000 products at once, 500 products are uploaded at a time. Unnecessary plugins are temporarily disabled, and the operation is performed during low traffic hours.

This approach not only raises the limit but also makes the operation safer. Because in large data operations, not only memory but also execution time, database write capacity, and server load are important. Additionally, e-commerce sites must ensure that the SSL certificate is active, payment integrations are up to date, and security layers are correctly configured. You can review the topics for SSL Certificate and E-commerce Hosting.

Performance Considerations

Increasing the memory limit is just one part of performance optimization. In fact, if misinterpreted, it can lead to the erroneous conclusion that “the higher the limit, the faster the site.” The memory limit allows WordPress to complete the process; however, it does not automatically fix unnecessary queries, heavy JavaScript files, unoptimized images, or poorly coded plugins.

For healthier performance, make the following checks:

  • Remove unused plugins; don’t just deactivate them.
  • Use PHP 8.2 or the latest stable PHP versions supported by your hosting.
  • Properly configure solutions like LiteSpeed Cache, Redis, or object caching.
  • Optimize images using WebP or AVIF formats.
  • Regularly clean up database tables.
  • Keep themes and plugins updated.
  • Periodically check error logs.

Especially on sites with many plugins, the most effective way to reduce memory consumption is to consolidate plugins that perform the same task. For example, if three different optimization plugins are running simultaneously, they can slow each other down and increase memory usage. A single, well-configured optimization solution often yields better results.

Security and File Editing Warnings

Since the wp-config.php file contains sensitive information, it should be edited with care for security reasons. Do not share the file via email, do not upload it to public support forums, and hide database information in screenshots. If you are using FTP, prefer SFTP whenever possible. Avoid editing files on shared networks.

File permissions are also important. Generally, more restricted permissions like 400, 440, or 600 can be preferred for wp-config.php; however, these values may vary depending on the server configuration. An incorrect permission value can prevent the site from reading the file or pose security risks. If you are unsure, ask your hosting support team for the recommended permission values.

To enhance WordPress security, the use of SSL, strong admin passwords, two-factor authentication, regular backups, and an updated plugin policy should be applied together. For more details, the WordPress Security Guide and SSL Certificates pages can be helpful.

Checklist If Issues Persist

You added the code, the limit seems raised, but the error continues; apply the following checklist:

  • Is the same constant defined a second time in wp-config.php?
  • Is the code above the correct line, meaning above the “stop editing” statement?
  • Is the PHP memory_limit value sufficient in the hosting panel?
  • Does the error occur when a specific plugin is activated?
  • Does the issue persist when the theme is changed?
  • Does the PHP error log show the same file or plugin repeatedly?
  • Is the site compatible with the updated PHP version?
  • Are there any excessively bloated log or temporary data tables in the database?
  • Do the hosting resource usage graphs hit CPU or I/O limits?

The answers to these questions will indicate whether the problem is genuinely a memory limit issue or a deeper optimization problem. For instance, if the same plugin file appears consistently in the error log, it may be necessary to update that plugin, use an alternative, or contact the developer.

SEO and Technical Health Perspective for 2026

In 2026 SEO standards, not only content quality but also technical user experience is critically important. Pages that fail to load due to memory errors, slow admin processes, failed order flows, and interrupted site experiences indirectly affect SEO performance. In an era where Google interprets user experience, accessibility, page stability, and crawlability signals better, technical errors should not be underestimated.

The memory limit issue can also cause search engine bots to receive a 500 error when crawling certain pages. This can particularly decrease indexing quality for large WordPress sites. Therefore, increasing memory via wp-config.php is not just a procedure that relieves the admin panel; it is an essential maintenance step that preserves the technical continuity of the site.

Moreover, technical health should be considered as a whole. Domain name DNS configuration, SSL installation, hosting performance, caching layer, mobile speed, security policy, and backup strategy should be thought of together. If you are starting a new project, planning Domain Record and Web Hosting solutions correctly at the initial stage reduces potential resource problems in the future.

Summary: The Safest Practice

The safest start for increasing the WordPress memory limit is to back up the wp-config.php file, add the line define('WP_MEMORY_LIMIT', '256M'); before the “stop editing” comment, and then test the change. If you perform heavy operations in the admin panel, you can also add define('WP_MAX_MEMORY_LIMIT', '512M');. If the server-side PHP memory_limit is set lower, you will need to raise this value from the hosting panel.

This process resolves most memory-related WordPress errors; however, for lasting performance, the number of plugins, theme quality, PHP version, caching structure, and hosting resources should also be regularly checked. Choosing a suitable infrastructure for your site's size yields healthier results in terms of both visitor experience and SEO continuity in the long run.

If you want to evaluate the resource needs of your WordPress site, explore suitable hosting options, or organize the SSL and domain aspects within the Hostragons infrastructure, you can check the relevant product pages. Analyzing your current site's traffic, plugin, and resource usage before making a purchase decision will be the best starting point.

Frequently Asked Questions

What should the WordPress memory limit be?

For simple sites, 128M is sufficient; for most modern WordPress sites, 256M is suitable; and for WooCommerce or heavily plugin-based structures, 512M is more appropriate. The most accurate value should be determined based on the number of plugins, traffic level, and hosting resources of the site.

Will the memory limit code added to wp-config.php break the site?

If the code is written correctly and added in the right position, it will not break the site. However, typos like missing quotes, forgotten semicolons, or adding outside the PHP block can cause white screens or PHP errors. Therefore, a file backup should be taken before the operation.

What is the difference between WP_MEMORY_LIMIT and WP_MAX_MEMORY_LIMIT?

WP_MEMORY_LIMIT sets the memory limit that WordPress will use for general frontend and normal operations. WP_MAX_MEMORY_LIMIT defines the upper limit that can be used for heavier operations, particularly in the admin panel.

I increased the limit with wp-config.php, but the error continues, why?

The PHP memory_limit on the hosting side may be set lower, it may have been defined a second time in the same constant file, or the issue may actually be a faulty plugin, an incompatible theme, or a database problem. PHP error logs and hosting resource graphs should be checked.

Does increasing the memory limit speed up a WordPress site?

Increasing the memory limit resolves operations that cannot be completed due to insufficient memory; however, it is not a standalone speed optimization. For real speed improvements, caching, image optimization, updated PHP version, quality hosting, and removal of unnecessary plugins should be implemented together.

Share this article:

Hostragons Team

Up-to-date guides from our expert team on hosting, servers, and domain names. Let's find the right solution for your project together.

Contact Us