add_permastruct() WordPress Function
The add_permastruct() function allows you to add a new permastruct for your site. A permastruct is a set of rules that determines how your site's URLs are structured. By default, WordPress uses a permastruct that looks like this: /%year%/%monthnum%/%day%/%postname%/ With the add_permastruct() function, you can change how your URLs are structured. For example, you could change the permastruct to this: /%postname%/ This would change your URLs to look like this: example.com/my-post/ You can also use the add_permastruct() function to add a new permastruct for a specific post type. For example, if you want to change the permastruct for your "Products" post type to this: /products/%postname%/ You would use the following code: add_permastruct('products', '/products/%postname%/');
add_permastruct( string $name, string $struct, array $args = array() ) #
Adds a permalink structure.
Description
See also
Parameters
- $name
(string)(Required)Name for permalink structure.
- $struct
(string)(Required)Permalink structure.
- $args
(array)(Optional) Arguments for building the rules from the permalink structure, see WP_Rewrite::add_permastruct() for full details.
Default value: array()
Source
File: wp-includes/rewrite.php
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 ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |