Remove /?doing_wp_cron from URL

Do you have “/?doing_wp_cron” in every URL on your WordPress site? It happened to me recently on one of my site and bothered me a lot, because it attached itself to every URL on the website.

The cause is actually very simple once I discovered the solution. When you see this happening on your WordPress site, it is a signal telling you that, ALTERNATE_WP_CRON is enabled. To disable this, locate this line in wp-config.php and remove it.

define( 'ALTERNATE_WP_CRON', true );

WordPress relies on WP Cron to execute scheduled tasks. But on some hosting server, WP Cron is disabled for their own concern. Enabling ALTERNATE_WP_CRON is one of the solution to keep scheduled task running as expected.

If you unfortunately have to use ALTERNATE_WP_CRON to keep scheduled post publishing on time, but don’t like the added /?doing_wp_cron query string attached to URL, here is a not so perfect solution:

#Rewrite Wp Cron Errors:
RewriteCond %{QUERY_STRING} (^|&)doing_wp_cron=[0-9]+.[0-9]+(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L]

The code snippet should be added to .HTACCESS file in root directory of /public_html.