Unfortunately, because of the way WordPress is set up, the permalinks cannot be used to their full potential. Although custom fields' values may be added into permalinks using certain customized hooks and hacks, it is still a somewhat complex procedure.
Permalink Manager may be a good option if you don't have any technical knowledge or just don't want to bother with code. Simply told, you may use the plugin to insert custom fields into WordPress URLs straight from the admin dashboard in a few simple clicks.
The features described in this article are exclusive to the Permalink Manager Pro and are not available in Permalink Manager Lite (free version).
Can WordPress Permalinks Include Custom Fields?
The original permalinks usually only have the rewrite base that is specific to the custom post type and the slug name that is based on the title:
https://example.com/team/john-doe/
Unfortunately, WordPress does not offer a built-in solution to enhance this permalink format by inserting additional data, such as custom fields. As a result, your options are limited to a third-party plugin or implementing a custom solution with rewrite rules.
Example
Assume that you need to update the URL format and include the department name and location in the single permalinks to reflect the locations of each of your employees.
One alternative is to establish a new hierarchical taxonomy and attach its multi-level slug to the URL of a single team member page.
Instead of registering a new taxonomy, you can apply a simpler solution and use Permalink Manager Pro to replace the custom field tag on the fly with the actual values of the fields:
https://example.com/team/%__country%/%__city%/%__department%/john-doe/
https://example.com/team/norway/oslo/management/john-doe/
The custom field/meta keys values may be appended to the custom permalinks of posts, pages, custom post types items (eg. WooCommerce products), categories, post tags, and custom taxonomies (eg. product categories).
Supported plugins
Advanced Custom Fields
The plugin allows you to add custom fields managed by Advanced Custom Fields to custom permalinks.
Inside the permalinks, you may include any of the following field types: "Text", "Number", "Relationship", "Taxonomy", "Select", "Post object", or "Date picker".
WooCommerce
Permalink Manager is also unquestionably the best option in one specific case. The plugin may be used to incorporate the SKU number in WooCommerce's product permalinks. A more comprehensive instruction may be found in this article.
Other plugins
Permalink Manager is compatible with nearly all custom fields plugins. It can be used to modify the permalink structure of custom post types and taxonomies that have been registered using the plugins including:
- Pods
- Toolset
- JetEngine
- Custom Post Type UI
- Metabox.io
In general, Permalink Manager Pro can be integrated with other plugins and themes using custom fields as long as they use the built-in custom field mechanism. If this is the case, you may use the meta field name as a Permastructure tag, as described below in the "Native/generic custom fields" section.
Instructions
Find the Custom Field Names
Permalink Manager has "out-of-the-box" support for custom fields created by some of the most popular third-party plugins. It may also be used to insert custom fields that are controlled by the native "Custom Fields" metabox or code snippets from third parties (eg. from The Meta Box Generator)
Native/generic custom fields & other plugins and themes
You can use the native custom fields if you don't want to install any additional plugins (such as Advanced Custom Fields). Enable the "Custom Fields" metabox in the "Screen Options" admin panel to identify their names.
The permastructure tags (displayed in “Name” column) are as follows:
- country for “Country”, ergo permastructure tag should be: %__country%
- city for “City”, ergo permastructure tag should be: %__city%
- department for “Department”, ergo permastructure tag should be: %__department%
MetaBox.io
The MetaBox plugin allows you to create custom fields in numerous ways. Using the same procedure as for "native/generic custom fields" is the simplest way to determine the names of custom fields.
Advanced Custom Fields
If you have used the "Advanced Custom Fields" plugin to create your custom fields, the procedure is slightly different. Below are some examples of metaboxes with fields managed by the ACF plugin.
To retrieve the custom field names, navigate to ACF's dashboard and choose the "Custom Fields" menu section in the admin sidebar navigation. Then, under the table labeled "Field Groups" select the group in which you specified your custom fields.
Following that, you should see the "Edit Field Group" page, which has the whole list of custom fields. Their names are displayed in the "Name" column.
Similarly, the meta keys (custom fields’ names) are in this case as follows:
- country for “Country”, ergo permastructure tag should be: %__country%
- city for “City”, ergo permastructure tag should be: %__city%
- department for “Department”, ergo permastructure tag should be: %__department%
A list of ACF custom fields that can be appended to permalinks
- Text field
- Number field
- Relationship field
- Taxonomy field
- Select field
- Post object field
- Date picker field
Toolset Types
As with the ACF plugin, you can quickly add custom fields specified using the "Toolset Types" plugin to WordPress permalinks. The Toolset Types-controlled metabox should be presented directly below the main text editor.
Click on the "Toolset" menu option in the left admin menu, then navigate to the "Post Fields" section to access the Toolset custom field names. The list containing "Post Field Groups" should now be visible. Click on the one where you specified which custom fields should be included in WordPress permalinks.
After opening the field settings, you must click on each field to see its slug. Please copy the slug if you want to use it in permastructure settings.
There is just one custom field slug shown above. With Permalink Manager, you can, of course, add multiple custom fields to WordPress permalinks.
The permastructure tags should look like this.
- country for “Country”, ergo permastructure tag should be: %__country%
- city for “City”, ergo permastructure tag should be: %__city%
- department for “Department”, ergo permastructure tag should be: %__department%
JetEngine
Custom fields handled by the JetEngine plugin are likewise supported by Permalink Manager Pro. To add the custom field to the permalink, you must first identify its name. It should be rather simple, given the names are displayed immediately in the metaboxes underneath the field labels:
In this example, the permastructure tag will be: %__country% (%__name_of_the_field%).
Add Custom Fields Tags to Permastructure Settings
After you've found and validated the names of the meta keys, you can use them as tags inside the permastructures for the "Team" custom post type. To adjust the Permalink Manager permastructure settings, go to the Permalink Manager dashboard ("Tools -> Permalink Manager -> Permastructures").
Reset Old Permalinks
How to Automatically Update Custom Permalink When Field Value Changes?
In general, Permalink Manager will use the default URI (with custom field values included) as a custom permalink once you create a new post with certain custom fields values.
Keep in mind that if you want the actual permalink to update automatically when you save or edit the article and change the custom field value, you will need to select "Auto-update the URI" option. You may enable it individually for each post or configure it globally for all posts. More information on how to activate this feature may be found here.
Obviously, you may override the default URI format by manually changing the permalinks of certain posts.