Fix to Saving Permalinks to fix 404’s
Here is fix for the pesky problem of having to resave your permalinks weekly or daily because of some unknown underlying issue. Add this little section of code to you functions.php file in your theme or child theme. The site will automatically rebuild the links for you. If after including this code you still have a problem consider changing the line flush_rewrite_rules in the second function to flush_rewrite_rules(true) to rebuild your .htaccess file as well. Good Luck!!
function prefix_setup_schedule() {
if ( ! wp_next_scheduled( 'prefix_hourly_event' ) ) {
wp_schedule_event( time(), 'hourly', 'prefix_hourly_event');
}
}
add_action( 'wp', 'prefix_setup_schedule' );
function prefix_do_this_hourly() {
flush_rewrite_rules(); //if this is not working then change this line to flush_rewrite_rules(true);
}
add_action( 'prefix_hourly_event', 'prefix_do_this_hourly' );
Comments are currently closed.