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 a filter hook, which is used for filtering 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
Basic Usage
To run the hook, copy the example below.
$post_rewrite = apply_filters('weplugins_post_rewrite_rules', $post_rewrite); if (!empty($post_rewrite)) { // everything has led up to this point... }
Adding a Hook Callback
The following example is for adding a hook callback.
// define the weplugins_post_rewrite_rules callback function weplugins_filter_post_rewrite_rules($post_rewrite) { // make filter magic happen here... return $post_rewrite; }; // add the filter add_filter('weplugins_post_rewrite_rules', 'weplugins_filter_post_rewrite_rules', 10, 1);
Removing a Hook Callback
To remove a hook callback, use the example below.
// remove the filter remove_filter('weplugins_post_rewrite_rules', 'weplugins_filter_post_rewrite_rules', 10, 1);
Contact Us
If you need customization, Contact Us.
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.