
Are you looking for a way to flush the permalinks once in every hour? While there’s probably a plugin for this, we have created a quick code snippet that you can use to flush permalinks once per hour cron job in WordPress.
To confirm permalinks are being flushed, simply add a comment just before # END WordPress in the .htaccess file. Once permalinks are flushed, the comment will disappear.
Instructions:
All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:
// Flush permalinks every hour add_action('my_hourly_event', 'do_this_hourly'); function my_activation() { if ( !wp_next_scheduled( 'my_hourly_event' ) ) { wp_schedule_event(time(), 'hourly', 'my_hourly_event'); } } add_action('wp', 'my_activation'); function do_this_hourly() { global $wp_rewrite; $wp_rewrite->flush_rules(); }
Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.
If you liked this code snippet, please consider checking out our other articles on the site like: 15 best content marketing plugins and how to create a WordPress donation form.
Comments Leave a Reply