This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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 );
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.