Adds a permalink structure.
Description
See also
Parameters
$name
stringrequired- Name for permalink structure.
$struct
stringrequired- Permalink structure.
$args
arrayoptional- Arguments for building the rules from the permalink structure, see WP_Rewrite::add_permastruct() for full details.
Default:
array()
Source
function add_permastruct( $name, $struct, $args = array() ) {
global $wp_rewrite;
// Back-compat for the old parameters: $with_front and $ep_mask.
if ( ! is_array( $args ) ) {
$args = array( 'with_front' => $args );
}
if ( func_num_args() === 4 ) {
$args['ep_mask'] = func_get_arg( 3 );
}
$wp_rewrite->add_permastruct( $name, $struct, $args );
}
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |
You can change rules to rewrite your type of posting as well as change your structure. Imagine that your permalink structure is like:
/locations/%k7_locations%
you can switch to
/test/%message%
output:
To add a custom URL-/permalink-structure, this function must be called on every request (not only once). I usually do this in the ‘init’ hook.
However, the related function
flush_rewrite_rules()
should only be called when the permalink structure changes.Sample: