Using WordPress ‘remove_permastruct()’ PHP function

The remove_permastruct() WordPress PHP function removes a permalink structure that was added using add_permastruct(). Built-in permalink structures cannot be removed.

Usage

To remove a custom permalink structure named ‘my_custom_structure’:

remove_permastruct('my_custom_structure');

Parameters

  • $name (string) – Required. The name of the permalink structure to be removed.

More information

See WordPress Developer Resources: remove_permastruct()

Examples

Removing a custom post type permalink structure

This example removes the custom permalink structure for a custom post type named ‘product’.

// Remove the custom post type 'product' permastruct
remove_permastruct('product');

This example removes the custom permalink structure for a custom taxonomy named ‘genre’.

// Remove the custom taxonomy 'genre' permastruct
remove_permastruct('genre');

This example demonstrates how to remove a custom permalink structure named ‘my_custom_structure’ when a plugin is deactivated.

// Remove the custom permastruct when the plugin is deactivated
function remove_my_custom_structure() {
    remove_permastruct('my_custom_structure');
}
register_deactivation_hook(__FILE__, 'remove_my_custom_structure');

This example removes multiple custom permalink structures named ‘custom_structure_1’ and ‘custom_structure_2’.

// Remove multiple custom permastructs
remove_permastruct('custom_structure_1');
remove_permastruct('custom_structure_2');

This example removes a custom permalink structure named ‘conditional_structure’ only if a specific condition is met.

// Remove the custom permastruct if a specific condition is met
if (some_condition_function()) {
    remove_permastruct('conditional_structure');
}