Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Wordpress

WordPress: Replace WP-Cron with Real Cron for Scheduled Tasks

- 27.05.26 - ErcanOPAK

⏰ WP-Cron Runs on Page Views — That’s Bad

WP-Cron triggers on visitor traffic. No visitors? Tasks never run. Replace with system cron for reliable scheduling.

🔧 Disable WP-Cron

# Add to wp-config.php
define('DISABLE_WP_CRON', true);

📦 Set Up System Cron

# Every 5 minutes
*/5 * * * * wget -q -O - https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

# Or using curl (more reliable)
*/5 * * * * curl -s https://yoursite.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1

# Or using PHP CLI (fastest)
*/5 * * * * php /path/to/wp-cron.php >/dev/null 2>&1

✅ Creating Custom Cron Events

// Schedule daily backup
if (!wp_next_scheduled('my_daily_backup')) {
    wp_schedule_event(time(), 'daily', 'my_daily_backup');
}

add_action('my_daily_backup', 'run_backup');

function run_backup() {
    // Export database, backup uploads
}

// Custom intervals
add_filter('cron_schedules', 'add_custom_intervals');
function add_custom_intervals($schedules) {
    $schedules['every_30_minutes'] = array(
        'interval' => 1800,
        'display' => __('Every 30 Minutes')
    );
    return $schedules;
}

💡 Debug Cron

  • Install WP Crontrol plugin to see all scheduled events
  • Check if cron is running: wp cron event list (WP-CLI)
  • Run cron manually: wp cron event run --due-now
  • Log cron output to debug: > /var/log/wp-cron.log 2>&1

“Site had low traffic. Scheduled backups never ran because WP-Cron needed visitors. Switched to system cron. Now backups run every day at 2 AM reliably.”

— WordPress Administrator

Related posts:

WordPress: Create Custom URL Structures with Rewrite Rules

WordPress: Use WP-CLI for Command-Line Site Management

WP “Menus Not Saving” — The Max Input Vars Killer

Post Views: 6

Post navigation

Photoshop: Master Blending Modes for Non-Destructive Effects
Kubernetes: Readiness vs Liveness Probes — What’s the Difference?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

June 2026
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  
« May    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (882)
  • Get the First and Last Word from a String or Sentence in SQL (838)
  • How to select distinct rows in a datatable in C# (808)
  • How to make theater mode the default for Youtube (805)
  • Add Constraint to SQL Table to ensure email contains @ (580)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (579)
  • Average of all values in a column that are not zero in SQL (538)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (505)
  • Find numbers with more than two decimal places in SQL (454)

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files
  • Ajax: Add Custom Headers to Fetch Requests
  • JavaScript: Use console.table to Display Arrays as Tables
  • HTML: Use Spellcheck Attribute to Enable Browser Spell Check
  • CSS: Use user-select to Prevent Text Selection
  • Windows 11: Use Snipping Tool for Instant Screenshots

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (953)
  • How to add default value for Entity Framework migrations for DateTime and Bool (882)
  • Get the First and Last Word from a String or Sentence in SQL (838)
  • How to select distinct rows in a datatable in C# (808)
  • How to make theater mode the default for Youtube (805)

Recent Posts

  • C#: Use String Interpolation Instead of Concatenation
  • C#: Use Tuples to Return Multiple Values from Methods
  • SQL: Use ISNULL and NULLIF for Smart NULL Handling
  • .NET Core: Use Data Annotations for Model Validation
  • Git: Use Git Clean to Remove Untracked Files

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com