By default, WordPress uses a pseudo-cron system: whenever a page is opened, it checks whether scheduled events are due and, if necessary, sends an internal request to wp-cron.php. This approach is convenient for simple websites, but it is not always suitable for projects with significant traffic.
If the endpoint is accessible from the internet, bots or attackers may call it repeatedly. This does not give them automatic access to the administration area, but it can create unnecessary PHP processes, trigger scheduled-task checks, and increase server load. A more reliable setup is to disable automatic execution through page visits, configure system cron via WP-CLI, and, when appropriate, block HTTP access to wp-cron.php.
What Happens When wp-cron.php Is Called
WP-Cron handles delayed and recurring actions such as publishing scheduled posts, sending emails, clearing temporary data, processing plugin queues, running synchronizations, creating backups, and other background tasks. With the default configuration, WordPress does not have a permanent system process that runs on a schedule. Instead, scheduled events are checked while the site is loading.
On a low-traffic website, this is usually unnoticeable. On a busy site or during peak periods, numerous requests can start unnecessary PHP processes. In addition, an externally accessible endpoint becomes a convenient target for repeated requests, even if each individual call is not critically dangerous.
- Calling wp-cron.php does not, by itself, log anyone into WordPress or bypass authentication.
- Blocking the endpoint does not cancel scheduled events; it only changes how they are triggered.
- After switching to system cron, responsibility for running tasks regularly is transferred to the server.
Disable Automatic Execution During Page Visits
First, prevent WordPress from starting the pseudo-cron during regular HTTP requests. Open wp-config.php and add the constant near the lines where the database settings and other core configuration options are already defined. It must be declared before the comment indicating the end of configuration editing.
- Do not add the constant again if DISABLE_WP_CRON is already present in the file.
- The value true disables automatic execution but does not disable WP-Cron events themselves.
- Back up wp-config.php before editing it and check the syntax after saving.
define('DISABLE_WP_CRON', true);
What This Setting Does Not Do
After DISABLE_WP_CRON is added, scheduled events remain in the database but are no longer triggered automatically when pages are opened. If no alternative mechanism is configured, emails, cleanup tasks, synchronizations, and other jobs will begin to run late or accumulate.
Configure System Cron via WP-CLI
The next step is to run events from the operating system. WP-CLI must be available on the server, and the command must run under a user with access to the WordPress files and database. In most cases, it is sufficient to run all events whose scheduled execution time has arrived every five minutes.
In the example below, replace the WordPress path and the path to the wp executable with the values used on your server. Add the command to the crontab of the appropriate system user.
- Run the command manually in the console before adding it to the schedule.
- Do not run WP-CLI as root unless necessary: this can create WordPress files with the wrong owner.
- If a task may run for a long time, use a lock to prevent two executions from overlapping.
*/5 * * * * /usr/bin/flock -n /tmp/wp-cron.lock /usr/local/bin/wp --path=/var/www/example cron event run --due-now >/dev/null 2>&1
Check WP-CLI Manually
Before switching to production mode, view the list of events and run those that are already due. If the command reports a database connection error, missing permissions, or an incorrect path, system cron will not be able to process tasks reliably.
- wp cron event list
- wp cron event run --due-now
How to Block External Access to wp-cron.php
If all events are launched locally through WP-CLI, HTTP access to /wp-cron.php can be denied at the web-server level. This reduces the surface available for mass external requests and does not interfere with the local WP-CLI command because it does not access the endpoint over the internet.
For Nginx, place the rule in the configuration of the required server block. After making the change, test the configuration and reload Nginx according to your system's procedures.
- Do not block the entire site or all PHP files instead of just this endpoint.
- Make sure the rule applies specifically to the root-level /wp-cron.php and not to unrelated URLs.
- The expected result of an external request after blocking is an access error, such as HTTP 403.
location = /wp-cron.php {
return 403;
}
Apache Alternative
For Apache, the restriction can be added to the virtual host configuration or to the .htaccess file in the WordPress root, if the server allows such rules. The syntax below is intended for modern Apache versions that support the Require directive.
<Files "wp-cron.php">
Require all denied
</Files>
Verify the System-Based Setup
The changes should be verified not only by checking the HTTP status code. It is important to confirm that specific plugins and integrations actually perform their deferred actions. Some extensions may use their own queue mechanisms or require HTTP access to WordPress, so consider the site's architecture before blocking the endpoint.
After configuring the system cron, wait for several execution cycles and review the results of key processes. If the system has PHP, web-server, or plugin error logs, check them for failed-task messages.
- Schedule a test post and verify that it is published on time.
- Check the delivery of system and transactional emails.
- Make sure import, export, synchronization, and image-processing queues are not accumulating.
- Check backups, temporary-data cleanup, and recurring reports.
- View the event list through WP-CLI and make sure overdue tasks are not growing without being processed.
- Verify that a direct external request to /wp-cron.php is actually blocked.
wp cron event list --fields=hook,next_run_gmt,next_run_relative, recurrence
Common Mistakes and Important Limitations
The most common mistake is adding DISABLE_WP_CRON and forgetting to configure system cron. In this case, the site stops running events automatically, but the symptoms may not appear until several hours or days later.
Another issue is using the wrong user or path in crontab. A command may work manually under one account but fail in cron because of a different environment, a missing PATH, or insufficient file permissions.
You should also avoid blocking the endpoint without checking whether an external service or a specific plugin relies on external HTTP requests. In that situation, first identify the dependency and move the relevant task to local execution or leave a controlled exception.
- Do not use multiple independent system cron jobs for the same purpose without a clear need.
- Do not treat an HTTP 403 response as proof that all WP-Cron events are running successfully.
- Do not redirect all errors to /dev/null during initial testing; save the output to a log first.
- If the server runs in a container or on managed hosting, system cron may be configured through a separate provider service.
Frequently asked questions
Does wp-cron.php need to be blocked on every WordPress site?
No. On small websites, the standard mechanism is often sufficient. Switching to system cron makes sense when there is significant traffic, regular load, or a requirement for predictable background-task execution.
Can wp-cron.php simply be deleted?
No. The file is part of WordPress and may be required for normal operation. It is safer to disable automatic execution with DISABLE_WP_CRON, configure WP-CLI, and restrict external HTTP access at the web-server level.
How often should system cron run?
For most sites, every five minutes is a practical starting interval. The exact interval depends on the tasks: stores, mailings, or integrations may require a different frequency. It is important that a new run does not start before the previous one has finished.
Will WP-CLI work if wp-cron.php is blocked?
Yes, provided that WP-CLI runs events locally and has the correct WordPress path, database access, and required permissions. The restriction applies to HTTP requests to the endpoint, not to direct command execution on the server.
Conclusion
Protecting wp-cron.php is not a matter of adding a single web-server rule; it requires the right execution model. First disable the pseudo-cron with DISABLE_WP_CRON, then configure regular WP-CLI execution through system cron, and only block external access to the endpoint after testing the setup.
After implementation, monitor not only server load but also outcomes: emails, queues, backups, and other background processes. This removes unnecessary external requests without the risk of silently stopping important WordPress tasks.