This code will call your function every hour.
// The 'if' condition is needed to make sure the scheduler runs only once
if ( ! wp_next_scheduled( 'my_custom_action' ) ){
wp_schedule_event( time(), 'hourly', 'my_custom_action' );
}
// Here we create our own action to attach to the scheduler
add_action( 'my_custom_action', 'update_content' );
It is also recommended you clear all scheduled events when you deactivate the plugin like so:
// The deactivation hook is executed when the plugin is deactivated
register_deactivation_hook( __FILE__, 'my_deactivation' );
function my_deactivation() {
wp_clear_scheduled_hook( 'my_custom_action' );
}
Note that if your website has zero visitors the cron will not run, image taken from here:

You can read more about wp_schedule_event() here.
Related Posts:
- How ( and mostly at what time ) can i prevent the alternate cron from running?
- How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
- Switch from wp-cron to a server cron job
- WordPress cron job running more than once
- Activate Plugin Automatically After Set Time
- Better way to run heavy scripts using WordPress database
- WordPress Cron function is not working
- Adding custom cron_schedule prior to wp_schedule_event
- Cron Job not working
- Uncaught Error: Call to undefined function wp_generate_attachment_metadata() @ wp-cron
- Schedule WordPress Auto-Updates to only run during business hours
- How do I email a new page password to somebody every month?
- What happens when wp_cron is deactivated in WordPress?
- wp_schedule_single_event function not working
- action-scheduler vs wp-background-processing
- Why is wp-cron only executing on page visit?
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- Does using WP-cron make the site slower for the user?
- wp_schedule_single_event not working: cron job is triggered but nothing gets executed
- How to make a implement queue for scheduling tasks in WordPress?
- Setup wp_schedule_event within a custom plugin
- How to set intervals in cron jobs?
- What causes wp_schedule_single_event to fire off?
- i need to make custom cron_schedule with custom interval time as a parameter into a custom payment gateway plugin wordpress
- Cron task gets removed from the schedule
- WP_CRON issue with UTC and local time
- WordPress crob job performance
- How to customize ‘recurrance’ of’ wp_schedule_event’?
- How to set-up multiple cron task with wp_schedule_event so that they do not overlap?
- Running a function using Crown WordPress on one day a week, for example, Mondays of every week
- WordPress “wp cron event run” as Siteground cron job
- Which approach for managing automatic updates would be more robust?
- Uninstall, Activate, Deactivate a plugin: typical features & how-to
- How do you debug plugins?
- Add multiple plugin directories
- What are the differences between WPINC and ABSPATH?
- Where do I put the code snippets I found here or somewhere else on the web?
- Giving Multiple Authors Access to a Plugin’s WP.org Repo
- Creating a default Custom Post Template that a Theme can override
- How do I check if my $wpdb->insert() was successful?
- Creating a theme option page?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Add post thumbnail from external image with plugin
- Is it possible to add an action to the currently running action?
- Created Widget Not Showing up on Admin Panel
- Action on post publish
- OOP: Display warning and deactivate the plugin if PHP version is less than 5.4
- wp_enqueue_scripts not working inside shortcode
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- unzip a folder on specific location and delete the zip file
- Handling jQuery Component Collision
- How to make a custom field as an editor in wordpress?
- How to keep users unique id stored in session in addition to IP in WordPress plugin?
- Plugin version is not showing up in wordpress.org plugin directory
- uninstall.php file in Plugin to clean DB
- How to get specific setting by settings_fields()?
- Save / Show multi line text in metabox
- Python with wordpress plugin
- Best way to initiate a class in a WP plugin?
- TinyMCE Styles Dropdown not adding html tags other than span
- Plugin Not Working After Being Uploaded To WordPress Plugin Repository
- Difference and examples of esc_attr__() and esc_attr_e()
- Change the display of Settings API (do_settings_sections)
- Issue running db create table query from static method
- How can I modify admin bar only if my plugin is loaded
- Set WordPress Transient Expiration via Variable Value
- Sanitizing file & directory form input
- Adding custom meta boxes to specified custom post type
- Override plugin class which has namespace
- Plugin create pages and use templates
- How to write to a separate PHP file in plugin settings
- Custom CSS not being added by plugin
- How to display results from a data table with an encrypted user id?
- How do i specify a url to which to redirect the user after he logs out from facebook?
- Translation for a text that is not printed on the screen
- Two plugins using the same CSS id
- Activation flow of a plugin in a multisite environment
- Checkbox show / hide output result
- How to show multi line output from metabox
- How to keep plugin (media-sync) running even the tab is closed?
- How does the WP repository determine that two plugins are the same when counting active installs?
- Visual composer custom element error
- How use wp_insert_post and add og:custom tags?
- Access remote SFTP server via WordPress login?
- How to change “Read More” text?
- How to use wp_editor and save its data in wp_posts table
- My WordPress activation hook isn’t working
- Performance considerations – postmeta table versus new table for custom posts with foreign keys?
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Echo custom admin field into a is_single()
- WordPress Boilerplate Plugin doesn’t see callback functions for add_settings_field and add_settings_section
- Hide ‘add to cart’ button for some products [duplicate]
- Exclude specifed files from plugin editor
- Add Flatr button to Sharing option
- Customize Multi-Column Tag Map to fetch specific post-type
- Upload Image to desired directory through plugin
- How can I delete the options from DB when the plugin is deleted?
- Allow manage_options capability for specific user only for specific plugin?
- What are the implications of having main plugin file name different to plugin slug?
- How to secure custom endpoint for rest api in WordPress