How To Edit Custom Permalinks In Bulk With Permastructures?

Managing and modifying each unique URL manually may be time-consuming. Fortunately, the plugin's Permastructure settings allow you to easily carry out bulk changes to custom permalinks.

Permastructures are an essential component of the Permalink Manager plugin. They tell the plugin how to generate the URLs for new posts, pages, and terms. You may use them to customize the permalink structure for each of post types and taxonomies.

How to Use Permastructures?

When you install Permalink Manager, it will not automatically change existing permalink formats provided by the in-built permalink system. The main purpose of Permastructures is to allow you to modify these existing permalink formats to your liking. Simply said, using permastructures gives you granular control over permalinks for all of your site's content types. You can optimize them for both SEO and user experience.

To sum up, until you manually edit it using the "URI Editor" the initial URL will be based on the permalink format (specified by the respective "Permastructure"). In other words, Permalink Manager will apply your permastructure settings to create a new custom permalink whenever a new post or term is published.

How to Edit Permastructures?

To change Permastructures, first go to the WordPress dashboard and then click "Permalink Manager" from the left-hand menu.

Once in the Permalink Manager settings, navigate to the "Permastructures" tab. A list of all available Permastructures can be found here. To alter a given Permastructure, simply click on the input field and make your modifications. Please remember to save your modifications.

Permastructures editor
As seen above, you may edit the permastructures for each post type and category independently. You have total control over how they are adjusted.

Please keep in mind that when you modify the permalink format using Permastructures in Permalink Manager, the new settings will only apply to new content.

This means the plugin will use your updated settings whenever you publish a new post, page, or add a new term. Therefore, after you change permastructures, existing custom permalinks will not be automatically changed to avoid unintentional modifications to content that might hurt SEO.

However, if you want modifications to be applied also to existing permalinks, please use the "Regenerate/reset" tool.

If you are unsure if the new "permastructures" settings are correct, you may examine the sample URL address within the "URI Editor". The new URL based on your updated permalink format (given in the "Permastructure" settings section) will be shown in the "Default custom permalink" row.

How Permastructures affect single permalinks
Custom permalink” field shows the current canonical permalink.
The “Default custom permalink” field indicates the default format of the custom permalink based on “Permastructure” settings.

How to Make Permastructure Formats Change Based on Certain Conditions?

As previously stated, Permastructures are a key component of the plugin, allowing you to specify the way your custom permalinks look like. While you can select a single general permalink format using the plugin's interface, there is a way to dynamically change this format using WordPress hooks.

Overriding the permastructure defined via the plugin interface is possible using the ' permalink_manager_filter_permastructure ' filter. This allows you to dynamically change the permalinks of your posts based on certain conditions.

For example, if you use this filter with the 'has_term()' function to build a code snippet, you can alter the permalinks of a post based on the category it is assigned to:

/**
* How to programmatically modify post permalink formats (permastructures)
*
* @param string $permastructure The permastructure string used when default custom permalink is generated.
* @param WP_Post|WP_Term $post Post or term object
* @return string The new, filtered permastructure string used when default custom permalink is generated (for new posts or existing ones if "Regenerate/reset" tool is used)
*/
function pm_filter_post_permastructure($permastructure, $post) {
	// Filter only 'Post' permalinks
	if(empty($post->post_type) || $post->post_type !== 'post') {
		return $permastructure;
	}
	// A. Post assigned to either 'Category A' or 'Category B'
	if(has_term(array('Category A', 'Category B'), 'category', $post)) {
		$permastructure = '%category%/%postname%';
	}
	// B. Post assigned to other categories
	else {
		$permastructure = '%year%/%monthnum%/%day%/%postname%';
	}
	return $permastructure;
}
add_filter('permalink_manager_filter_permastructure', 'pm_filter_post_permastructure', 10, 2);

The code above is just a basic example. For further information and examples, please visit a dedicated page.

Frequently Asked Questions

Why Is the Slug Automatically Appended?

By default, Permalink Manager automatically appends the slugs to the end of custom permalinks. If you would like to disable this, please go the Permastructure section where you have already configured custom permalink formats. Then, below the input boxes, click on the "Show additional settings" button.

"Show additional settings" button

Now, when the additional container appears, select "Do not automatically append the slug" and save the changes.

Do not automatically append the slug settings

If you would like to manually tweak the custom permalinks, you can use the Bulk URI Editor. The items are grouped by post type and taxonomy for your convenience.

Bulk edit permalinks using URI Editor

The native slugs are used by WordPress in posts’ and terms’ original permalinks. They are produced after the article or term is published and hence they remain unchanged even if you update the post/term title later. In certain cases, it may be preferable to dynamically use the title rather than the "static" slug. Please see the following notes for further information how to make Permalink Manager use the titles in the custom permalinks.

Slugs mode

Permalink Manager, like WordPress, will use native slugs by default. In the plugin setting ("Slugs mode" field) you may decide whether either native slugs or actual post titles should be included when new permalinks are generated.

"Slugs mode" field

Auto-update permalinks

It is important to remember that Permalink Manager will not update your custom permalinks automatically. If you want it to update automatically, for example, when the post/term title changes, turn on "Auto-update permalinks" mode.

"Permalink update" global settings

How to Replace the Slugs With Post/Term IDs?

You can use Permalink Manager to add element IDs to custom permalinks by using dedicated tag: %post_id% for posts and %term_id% for terms. However, if you want to use it to totally replace the slug, you will need to do a few further steps.

To begin, you must activate the "Do not automatically attach the slug" option attached to permastructure settings in order to use post/term IDs instead of slugs. Furthermore, you will need to use extra code snippet to help Permalink Manager recognize URLs with numeric endings and separate them from lookalike pagination endpoints.

add_filter('permalink_manager_deep_uri_detect', '__return_true');

Once it is done, you should adjust the permastructures settings and use %post_id% tag

How to add post ids to custom permalinks?

Go up