flush_rewrite_rules( bool $hard = true )
Remove rewrite rules and then recreate rewrite rules.
Description Description
Parameters Parameters
- $hard
-
(bool) (Optional) Whether to update .htaccess (hard flush) or just update rewrite_rules transient (soft flush). Default is true (hard).
Default value: true
Source Source
File: wp-includes/rewrite.php
function flush_rewrite_rules( $hard = true ) { global $wp_rewrite; if ( is_callable( array( $wp_rewrite, 'flush_rules' ) ) ) { $wp_rewrite->flush_rules( $hard ); } }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
If you want to flush rules while updating posts based on post type:
Expand full source codeCollapse full source code
Expand full source codeCollapse full source code
This is how you would flush rules on theme activation:
If you’re developing a theme, while building it you can use this snippet of code that will flush rewrite rules when the file containing it is changed, or every 48 hours:
Expand full source codeCollapse full source code
Feedback
“Flushing” the rewrite rules should only happen in wp-admin, see https://core.trac.wordpress.org/ticket/44142. It is possible to do from the front-end while developing a theme or a plugin, but is a pretty bad idea if ever done in production.In that terms I’d add:
if ( ! is_admin() ) { return; }
at the top of the above function. — By Andrew Ozz —This is how you would flush rewrite rules when a plugin is activated or deactivated:
Expand full source codeCollapse full source code
Expand full source codeCollapse full source code