add_permastruct( string $name, string $struct, array $args = array() )

Add permalink structure.


Description Description

See also See also


Top ↑

Parameters 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 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

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Marcio Zebedeu

    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%

    global $wp_rewrite;
    $args = array(
        'with_front' => true,
        'ep_mask' => 3,
        'paged' => 1,
        'feed' => 1,
        'forcomments' => 0,
        'walk_dirs' => 1,
        'endpoints' => 1
    );
    add_permastruct( 'locations', 'test/%message/', $args);

    output:

    Array
    (
        [with_front] => 1
        [ep_mask] => 3
        [paged] => 1
        [feed] => 1
        [forcomments] => 0
        [walk_dirs] => 1
        [endpoints] => 1
        [struct] => /test/%message/%
    )

You must log in before being able to contribute a note or feedback.