I have a problem I'm wondering, need someone to help.

I am doing a function that sends email to followers weekly and monthly. Currently, I have written a function to use, but one thing is I do not know how to use cron to run WP. Can anybody suggest or guide me to make? Thanks very much :)

  • 1
    Read the documentation for starters. – Jacob Peattie Feb 1 '18 at 2:05
  • Hi, thanks for your help. However, I want build cron without the plugin? Have you another idea? – Quang Hoang Feb 1 '18 at 2:10
  • What plugin? RTFA. – Jacob Peattie Feb 1 '18 at 3:08
  • Well, you have to write some code to schedule cron events. Either you do this in a plugin or your theme, but ideally it should be a plugin. – swissspidy Feb 1 '18 at 9:06
  • @swissspidy Thanks for your help, I will try it :) – Quang Hoang Feb 1 '18 at 9:10

i got this proplem with hight load in my wppit.com so i checked my cpanel and i found the cronjob casue this hiegh load and because WordPress has to work on all sort of different platforms, OS's and configurations, it can't rely that there will be a cronjob service on the server that can handle scheduled tasks. This is why WordPress developers have created a workaround - the wp-cron.php file in your main WordPress folder is executed every time someone loads a page. It then checks if there's a scheduled task to be done and executes it if necessary.

However, in some cases, this file may become target of a DOS attack, or caching plugins can interfere with its execution which can cause either a lot of server load or the scheduled tasks may not execute properly and timely. This is why, you can substitute this constant file execution with a real cron job.

First, you need to disable the script to be executed every time someone loads one of your pages. To do this, open the wp-config.php file in your main WordPress folder and add the following line before the "/* That's all, stop editing! Happy blogging. */" line: 1

define('DISABLE_WP_CRON', true);

Once you do that, you need to setup a real cron job and execute the wp-cron.php file with it. You don't want to trigger it too often - 30 minutes should be fine for most of the websites. To do this, login to your cPanel and go to the Cron jobs tool located in the Advanced section.

Then, add the following command to be executed every 30 minutes: 1

wget -q -O - http://yourdomain.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

You need to replace yourdomain.com with your actual domain name. The Cron jobs tool has some of the most common schedules preset, so you can just select Every 30 minutes from the minutes drop-down and place a "*" symbol in the others.

more information here https://www.siteground.com/tutorials/wordpress/real-cron-job/


Your hosting place should have an option on their control panel for adding CRON jobs. If this is self-hosted, you'll need to look for information specific to your operating system; ask the googles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.