flush_rewrite_rules() WordPress Function

The flush_rewrite_rules() function is used to refresh the permalinks in WordPress. This is useful when you change the permalink structure of your site, or when you change the URL of a post.

flush_rewrite_rules( bool $hard = true ) #

Removes rewrite rules and then recreate rewrite rules.


Parameters

$hard

(bool)(Optional)Whether to update .htaccess (hard flush) or just update rewrite_rules option (soft flush). Default is true (hard).

Default value: true


Top ↑

More Information

This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when necessary.


Top ↑

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 );
	}
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.