post_rewrite_rules filter
Filters rewrite rules used for “post” archives.
apply_filters( 'post_rewrite_rules', string[] $post_rewrite )
Description
This is filter hook , which is used for filters the rewrite rules used for “post” archives.
With post_rewrite_rules
, you can easily change permalinks not only to the post but also to its comments, attachments, etc. Original permalinks you can keep or replace with new ones.
Parameters
- $post_rewrite : (string[]) Array of rewrite rules for posts, keyed by their regex pattern.
Live Example
apply_filters( 'post_rewrite_rules', string[] $post_rewrite )
To run the hook, copy the example below.
$post_rewrite = apply_filters( 'post_rewrite_rules', $post_rewrite ); if ( !empty( $post_rewrite ) ) { // everything has led up to this point... }
The following example is for adding a hook callback.
// define the post_rewrite_rules callback function filter_post_rewrite_rules( $post_rewrite ) { // make filter magic happen here... return $post_rewrite; }; // add the filter add_filter( 'post_rewrite_rules', 'filter_post_rewrite_rules', 10, 1 );
To remove a hook callback, use the example below.
// remove the filter remove_filter( 'post_rewrite_rules', 'filter_post_rewrite_rules', 10, 1 );