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

Top ↑

See also


Top ↑

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()


Top ↑

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
3.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.