{"id":4641,"date":"2022-05-20T16:03:54","date_gmt":"2022-05-20T13:03:54","guid":{"rendered":"https:\/\/www.scalahosting.com\/kb\/?p=4641"},"modified":"2025-11-27T13:36:43","modified_gmt":"2025-11-27T11:36:43","slug":"how-to-replace-wordpress-cron-with-a-real-cron-job","status":"publish","type":"post","link":"https:\/\/www.scalahosting.com\/kb\/how-to-replace-wordpress-cron-with-a-real-cron-job\/","title":{"rendered":"Replace WP-Cron with Real Cron Job"},"content":{"rendered":"\n<p><span style=\"font-weight: 400;\">You don&#8217;t necessarily need to be a technical wizard to build a website, but this doesn&#8217;t mean there is no learning curve ahead of you. If you use a <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/what-is-wordpress-how-does-it-work\/\"><b>CMS like WordPress<\/b><\/a><span style=\"font-weight: 400;\">, you&#8217;ll probably get to grips with the <\/span><b>app&#8217;s basic functions<\/b><span style=\"font-weight: 400;\"> fairly quickly. However, if you want to develop a successful project, you&#8217;ll need to have a better understanding of how it all works.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Among other things, this means figuring out <\/span><b>what cron jobs do<\/b><span style=\"font-weight: 400;\"> and setting them up correctly. Let&#8217;s see if we can help.<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>What is a Cron Job?<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Although most of them remain hidden, your computer performs tasks all the time. There are many examples. Your email client regularly <\/span><b>connects to the mail server <\/b><span style=\"font-weight: 400;\">to check for messages, your operating system goes online to ensure it displays the correct time, etc.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If you use Windows, all these processes are controlled by the <\/span><b>Task Scheduler<\/b><span style=\"font-weight: 400;\">. If you run a Unix-based OS like Linux or macOS, they are taken care of by <\/span><b>cron<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Cron is <\/span><b>a command-line utility<\/b><span style=\"font-weight: 400;\"> that runs commands and scripts <\/span><b>at fixed times or preset periods<\/b><span style=\"font-weight: 400;\">. In addition to app-specific jobs, it&#8217;s responsible for <\/span><b>automating many of the tasks related to the optimal performance of the operating system<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Cron jobs run periodically, and the schedule is kept in <\/span><b>a crontab file or cron table<\/b><span style=\"font-weight: 400;\">. Every user on the machine can have their own cron table, and the system-wide crontab is usually located in either <\/span><i><span style=\"font-weight: 400;\">\/etc <\/span><\/i><span style=\"font-weight: 400;\">or <\/span><i><span style=\"font-weight: 400;\">\/etc\/cron.d\/<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Crontabs can be edited with a text editor, and each line in them represents a separate cron job. The syntax looks like this:<\/span><\/p>\n\n\n\n<p><b><i>* * * * * [command or path to script]<\/i><\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">The asterisks can have different values, determining <\/span><b>when the cron job is to be executed<\/b><span style=\"font-weight: 400;\">. The five asterisks represent <\/span><b>the minute, hour, day of the month, month, and day of the week<\/b><span style=\"font-weight: 400;\">, respectively. After that, you have the shell command or application to be executed.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">For example, if we want the shell to output &#8220;hello world&#8221; every day at five minutes past midnight, we&#8217;ll have:<\/span><\/p>\n\n\n\n<p><b><i>5 0 * * * echo hello world<\/i><\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If we want to have the same output at five past midnight on every fifteenth day of the month, we&#8217;ll have:<\/span><\/p>\n\n\n\n<p><b><i>5 0 15 * * echo hello world<\/i><\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">If we want it to happen every year on the fifteenth of April at five past midnight, we&#8217;ll have:<\/span><\/p>\n\n\n\n<p><b><i>5 0 15 4 * echo hello world<\/i><\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Cron jobs on a web server are just as important. Often, they&#8217;re created manually by site owners who need to automate tasks related to their projects&#8217; performance.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">But how does WordPress handle them?<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>WordPress and Cron Jobs<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">The smooth operation of a WordPress project relies on <\/span><b>automated tasks<\/b><span style=\"font-weight: 400;\">. For example, if you want to keep your<\/span><b> CMS, themes, and plugins up-to-date<\/b><span style=\"font-weight: 400;\">, WordPress must periodically check for new versions. Scheduling posts is also a widely used feature that relies on automation. However, by default, <\/span><b>WordPress doesn&#8217;t use cron jobs<\/b><span style=\"font-weight: 400;\"> for several reasons.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">For one, although it&#8217;s rare, WordPress can run on Windows, in which case, any attempts to use cron would be unsuccessful. And even if we look at Linux only, we&#8217;ll see that the<\/span><b> cron configurations vary wildly from server to server.<\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">That&#8217;s why WordPress instead relies on the <\/span><b>wp-cron.php<\/b><span style=\"font-weight: 400;\"> file to schedule and automate tasks. Although it has the word &#8220;cron&#8221; in its name, the concept is different.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Instead of keeping track of time and running commands according to a pre-selected schedule, wp-cron.php is <\/span><b>loaded every time a user visits the website<\/b><span style=\"font-weight: 400;\">. If any tasks can be executed, wp-cron carries on with them automatically. Theoretically, it seems like a viable alternative, but in reality, it has a few inherent problems.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">For one, the execution of tasks may not be as reliable as you&#8217;d wish. The wp-cron.php file is <\/span><b>only loaded when there&#8217;s an active HTTP request to the site<\/b><span style=\"font-weight: 400;\">, so if there&#8217;s no traffic, it may fail to work as expected.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Furthermore, wp-cron.php is yet another file that the server needs to load every time a visitor access your site. This <\/span><b>increases the load and consumes bandwidth<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">It&#8217;s not uncommon for hackers to target the cron file either, and it could cause<\/span><b> conflicts with some caching plugins<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><b>Linux&#8217;s cron system<\/b><span style=\"font-weight: 400;\"> is definitely more reliable, and it can help you improve the performance and reliability of your WordPress website. Before you can use it to automate your tasks, however, it&#8217;s a good idea to disable wp-cron.php.<\/span><b><\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Disabling wp-cron.php<\/b><b><\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">A simple modification of the wp-config.php file can disable the default WordPress automated task behavior. You can use an <\/span><a href=\"https:\/\/www.scalahosting.com\/kb\/how-to-setup-ftp-using-filezilla\/\"><b>FTP client<\/b><\/a><span style=\"font-weight: 400;\">, <\/span><b>SSH, or your <\/b><a href=\"https:\/\/www.scalahosting.com\/spanel.html\"><b>web hosting control panel&#8217;s<\/b><\/a><b> File Manager <\/b><span style=\"font-weight: 400;\">to access wp-config.php in your site&#8217;s document root.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">As we&#8217;re talking about the primary <\/span><b>WordPress configuration file<\/b><span style=\"font-weight: 400;\">, it might not be a good idea to create <\/span><b>a backup copy of it first<\/b><span style=\"font-weight: 400;\">, just in case.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Open the file and add the following above the line that says &#8220;<\/span><i><span style=\"font-weight: 400;\">\/* That&#8217;s all, stop editing! Happy publishing. *\/<\/span><\/i><span style=\"font-weight: 400;\">&#8220;:<\/span><\/p>\n\n\n\n<p class=\"alert-orange\"><b><i>define(&#8216;DISABLE_WP_CRON&#8217;, true);<\/i><\/b><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">Make sure you save the changes and <\/span><b>re-upload the file if you&#8217;re using FTP.<\/b><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><b>Creating a Regular Cron Job<\/b><\/h2>\n\n\n\n<p><span style=\"font-weight: 400;\">Disabling wp-cron may help you optimize your website&#8217;s performance and resource usage, but it will also <\/span><b>disable the automated jobs<\/b><span style=\"font-weight: 400;\"> that the PHP file takes care of by default. For them, you&#8217;ll need regular Linux cron jobs.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">There are a couple of ways of setting up a cron job. If you prefer the command line, you can use the <\/span><b><i>crontab -e <\/i><\/b><span style=\"font-weight: 400;\">command and save a new cron using the syntax we discussed a couple of sections ago. However, an easier option would be to use the utility in your web hosting control panel.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">All <\/span><b>popular management platforms<\/b><span style=\"font-weight: 400;\"> have a graphical interface for setting up cron jobs. They may differ slightly in terms of design, but they should all offer the options you see in the screenshot below.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"856\" height=\"869\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-3.png\" alt=\"Replace WP-Cron with Real Cron Job, Creating a Regular Cron Job\" class=\"wp-image-4644\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-3.png 856w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-3-296x300.png 296w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/1-3-768x780.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">This is what SPanel users see when they open the <\/span><b>Cron Jobs <\/b><span style=\"font-weight: 400;\">tool on the home page of the User Interface. You can determine when a cron job should be executed by entering values in the <\/span><b>Minutes<\/b><span style=\"font-weight: 400;\">, <\/span><b>Hours<\/b><span style=\"font-weight: 400;\">, <\/span><b>Date<\/b><span style=\"font-weight: 400;\">, <\/span><b>Month<\/b><span style=\"font-weight: 400;\">, and <\/span><b>Weekday<\/b><span style=\"font-weight: 400;\"> fields, or you can use the <\/span><b>Common Settings <\/b><span style=\"font-weight: 400;\">in the drop-down menus.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"817\" height=\"479\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-3.png\" alt=\"Replace WP-Cron with Real Cron Job, Creating a Regular Cron Job 2\" class=\"wp-image-4645\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-3.png 817w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-3-300x176.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/2-3-768x450.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><span style=\"font-weight: 400;\">The <\/span><b>Cron command <\/b><span style=\"font-weight: 400;\">field determines what the cron job is going to do. You can enter a regular command or do what most developers prefer and put <\/span><b>several tasks into a single script<\/b><span style=\"font-weight: 400;\">.<\/span><\/p>\n\n\n\n<p><span style=\"font-weight: 400;\">This does require diving deeper into the world of programming, but the internet is overflowing with resources, and you can also borrow ready-made scripts that take care of various site maintenance tasks. For example, with just three <\/span><a href=\"https:\/\/www.scalahosting.com\/blog\/what-is-wp-cli-a-beginners-guide\/\"><b>WP-CLI<\/b><\/a><span style=\"font-weight: 400;\"> commands and four lines of code, you can have <\/span><b>WordPress automatically check for and install new versions of the core, plugins, and themes.<\/b><\/p>\n\n\n\n<p><b>This is what the script should look like:<\/b><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"535\" height=\"131\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/3-3.png\" alt=\"Replace WP-Cron with Real Cron Job, Creating a Regular Cron Job 3\" class=\"wp-image-4642\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/3-3.png 535w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/3-3-300x73.png 300w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>\n\n\n<p><br><span style=\"font-weight: 400;\">Bear in mind that this is a <\/span><b>very simple script<\/b><span style=\"font-weight: 400;\">. A bit more research will show you that you can easily broaden the range of tasks you do with a single file and a cron job. When you&#8217;re ready with the script, enter its path into the <\/span><b>Cron command <\/b><span style=\"font-weight: 400;\">field to set it up to work with a cron job.<\/span><\/p>\n\n\n<div class=\"wp-block-image mpg-gallery\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"830\" height=\"504\" src=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-3.png\" alt=\"Replace WP-Cron with Real Cron Job, Creating a Regular Cron Job 4\" class=\"wp-image-4643\" srcset=\"https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-3.png 830w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-3-300x182.png 300w, https:\/\/www.scalahosting.com\/kb\/wp-content\/uploads\/2022\/05\/4-3-768x466.png 768w\" sizes=\"(max-width: 361px) 660px, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 910px, 1140px\" \/><\/figure>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>You don&#8217;t necessarily need to be a technical wizard to build a website, but this doesn&#8217;t mean there is no learning curve ahead of you. If you use a CMS like WordPress, you&#8217;ll probably get to grips with the app&#8217;s basic functions fairly quickly. However, if you want to develop a successful project, you&#8217;ll need [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5547,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"none","_seopress_titles_title":"Replace WP-Cron with Real Cron Job | ScalaHosting KB","_seopress_titles_desc":"","_seopress_robots_index":"","_seopress_analysis_target_kw":"","footnotes":""},"categories":[34],"tags":[],"class_list":["post-4641","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-hosting"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4641","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/comments?post=4641"}],"version-history":[{"count":8,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4641\/revisions"}],"predecessor-version":[{"id":5856,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/posts\/4641\/revisions\/5856"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media\/5547"}],"wp:attachment":[{"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/media?parent=4641"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/categories?post=4641"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scalahosting.com\/kb\/wp-json\/wp\/v2\/tags?post=4641"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}