To automatically flush permalinks every hour, use the following code:
- Hook the scheduling function to
init. - Schedule an hourly event if not already scheduled.
- Hook the scheduled event to a function.
- Define the function to flush rewrite rules.
// Hook the scheduling function
add_action( 'init', 'schedule_my_hourly_event' );
// Schedule the event
function schedule_my_hourly_event() {
if ( ! wp_next_scheduled( 'my_hourly_event' ) ) {
wp_schedule_event( time(), 'hourly', 'my_hourly_event' );
}
}
// Hook the event to a function
add_action( 'my_hourly_event', 'my_flush_rewrite_rules' );
// Function to flush rewrite rules
function my_flush_rewrite_rules() {
flush_rewrite_rules();
}
Related Posts:
- how to get permalink structure with php
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- WordPress theme showing blank page
- Permalink changes after several minutes after saving post
- What is the proper way to call a function (from functions.php) on a link click?
- redirect 301 with special character like WIX site “#!”
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- How to extract URLs from wordpress taxonomies
- Execute wp_after_insert_post after the permalink is customized
- Modify the permalink structure for a specific category
- Processing data and redirecting with query string
- How do I link a button I created in theme customizer to a function?
- Echo string and function?
- How to change menu labels
- jQuery code not working when included in functions.php
- Fatal Errors on pluggable.php
- Log in / Log Out Custom Button
- Adding wrapper elements in the_date() like in the_title()?
- How to obtain the current website URL in my theme?
- Notify users only on post publish
- Plugin Generate Unexpected output during activation
- Remove Custom Divs from AMP pages
- Read array in php?
- Tell WP register script to load a script only when the entire page is loaded
- Can’t save php string to a custom field
- get_template_directory adding FTP root folders in urls
- Fatal error: Call to undefined function register_new_user()
- stripping tags from excerpt in WordPress is not working
- Is it possible to display a DIV to not logged in users and then change it for users who are logged in?
- PHP code for displaying WordPress posts in a static page not working
- Remove extract from function
- Undefined offset: 3 in custom function
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Post not populating for custom post type based on category selection
- How to add data to a custom field at the wp_users table?
- call_user_func_array() expects parameter 1 to be a valid callback, function ‘———-‘ not found or invalid function name
- How can I use custom menus with a Bootstrap WordPress theme?
- How to make a cookie be on the whole site instead of being on a specific page/
- Search only working on front page (index) , not working on other pages
- Child Theme’s Read More Text
- call a string/function from database
- Dynamic Menu drops pages?
- Get date function not working
- How to implement __() function in my theme’s php file?
- Can/should we delete wordpress cron jobs with no action?
- Database entry removed on browser refresh, Ajax PHP jQuery
- How a HTML form can trigger a PHP function?
- Allow a user or role to view drafts and previews, but not other admin privileges?
- Display Visual Composer shortcode if a post belongs in specific categories
- Add Featured Image to Existing Post
- How to get latest post ID in functions.php?
- Billing detail page doesn’t work after I’ve changed the order of the Woocommerce navigation
- Get current user id in function php
- Proper way to remove html code on child theme
- Trying to add Custom Post Type to this functions.php command
- Apply function.php filter only if url not has /amp/
- Preventing direct access to a page in WordPress
- How to use data URL in WordPress?
- Flushing the slug base has no effect and does not change
- How can I prevent a shortcode div from extending beyond its boundaries?
- Display a custom name when the user has no name settle in his account
- Multiple cron jobs vs daily cron job doing multiple things? Which one yields better performance and scalability?
- Discount in the specific product title using keyword ( Woocoommerce )
- WordPress generates weird permalinks
- Modify post image in full size
- How to link all featured images to custom url in single.php for only non-logged-in users?
- JQuery modal not loading video on popup, only displaying it after multiple reopenings
- Get user by meta data key and velue
- Logo custom width not implementing
- Woocommerce textarea format ignored
- custom post type column countdown
- Add another role to a user when they click a button?
- Using wordpress functions in class and change my code to OOP PHP
- Creating wordpress user registration form
- Add missing alt tag to featured images for “storefront” theme
- Notice: Undefined index: post_title error
- Unable to pass arguments to function used in add_action
- Load admin bar without wp_head or wp_footer [duplicate]
- Allow user to select location and then set cookie for location in WordPress
- Using Tag Groups: Displaying groups and adjacent tags of current post
- My query keeps looping infinitely ! how to stop it?
- Highlight Single Page Ancestor
- How to create “page” used for generating PDF? [closed]
- Registration form not registering First and Last name
- Removing get_template_part in child theme
- Merge / Combine two php functions for Previous and Next Link with Thumbnail
- set new link as permalink
- Why isn’t my custom function kicking in from my functions.php file?
- str_replace not responding in functions.php [closed]
- append links with unique number string
- Shortcoding with Divs
- Display a list of users with avatar filterable with alphabets
- Change default comments form title [duplicate]
- How to get the rating value of each comment
- Adding php within a return statement [closed]
- Displaying categories
- Error in php code
- Add any username as link prefix and show data from that specific user’s profile on wordpress pages – with no login required
- Replace the image of a product with its video in the shop page