The native WordPress settings and rewrite rules does not allow to fully customize the posts & categories permalinks. Although, custom fields values can be inserted to permalinks with some tailored hooks & hacks, it is still a quite complicated operation.
Permalink Manager is currently the only plugin that allows you to insert the custom fields to WordPress in just a few steps directly from the admin dashboard.
The functionalities presented in this post are available only in Permalink Manager Pro.
Sample permalink format with custom fields
Original permalinks:
http://example.com/team/john-doe/ http://example.com/team/max-mustermann/ http://example.com/team/jan-kowalski/
New permalink format with custom fields:
http://example.com/team/%__country%/%__city%/%__department%/john-doe/
New WordPress permalinks with custom fields added via Permalink Manager:
http://example.com/team/norway/oslo/management/john-doe/ http://example.com/team/germany/berlin/accounting/max-mustermann/ http://example.com/team/poland/warsaw/hr/jan-kowalski/
You can freely adjust the permastructures settings and add the custom fields any way you like. It will work also in more complex scenarios – below you can see only a sample example.
Please note that this tutorial shows only example custom post type name and custom fields (meta tags). They may be completely different in your particular case.
Where can you insert the custom fields?
Permalink Manager allows to append the custom field/meta keys values to the custom permalinks of:
- posts
- pages
- custom post types items, eg. WooCommerce products
- categories
- post tags
- custom taxonomies, eg. WooCommerce product categories
Why it is convenient to use Permalink Manager to add custom fields to permalinks?
For instance, let’s assume that you want to add country, city and department names to our team members single pages’ permalinks to suggest where each of our employees work. Theoretically you can register a new, custom hierarchical taxonomy and add their multi-level slug to a single team-member page permalink. Anyway, in some specific cases like this, it would be more clever and consistent to insert this data using custom fields.
There is also one specific situation when Permalink Manager is unarguably the best choice. The plugin can be used to include the SKU number in the product permalinks handled by WooCommerce. In this article, you can find a more detailed instruction.
Instructions
Find the custom field names
Permalink Manager supports custom fields added with Toolset Types & Advanced Custom Fields “out-of-the-box”. You can also use it to insert custom fields controlled from native “Custom Fields” metabox or 3rd party code snippets (eg. from The Meta Box Generator).
Native/generic custom fields
If you do not use any third party plugin (eg. Advanced Custom Fields) to handle the meta keys you can find the names of custom fields using “Custom Fields” metabox. You can enable it from “Screen Options“ section.
After you activate “Custom Fields” metabox, you will need to scroll down the editor page a bit. You will find the table with meta keys displayed somewhere below the content editor.
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%
Advanced Custom Fields
You can insert the custom fields value also if they are set-up with “Advanced Custom Fields” plugin. The process looks very similar. Below you can see some sample metabox with the fields controlled by ACF plugin.
To find the custom field names, you will need to go to ACF’s dashboard by clicking on “Custom Fields” menu section in the admin sidebar navigation. Then in the table with “Field Groups” click on the specific group where you defined your custom fields.
After that, you should see “Edit Field Group” page with the full list of custom fields. You can find their names displayed in “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 in the case of ACF plugin, you can also easily add to WordPress permalinks custom fields set with “Toolset Types” plugin. The metabox controlled by Toolset Types should be displayed just below the main content editor:
To find the Toolset custom field names, please click on “Toolset” menu item in the left admin menu and then go to “Post Fields” section. Now the list with “Post Field Groups” should be displayed. Click on the one where you defined the custom fields that should be added to WordPress permalinks.
After you open the field settings, you will need to click on each field to display its slug. The slug should be used in permastructure tags in Permalink Manager permastructure settings:
Above, you can see only a single custom field slug. Of course you can add multiple custom fields to WordPress permalinks with Permalink Manager. The permastructure tags should be 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%
JetEngine
Permalink Manager Pro supports also custom fields controlled with JetEngine plugin. To add the custom field to the permalink, at first, you will need to find its name. It should be pretty easy, as the names are displayed directly in the metaboxes below the field labels:
The needed permastructure tag will be in this case: %__country% (%__NAME_OF_THE_FIELD%). Please check below instructions to see how exactly the tag should be used.
Add custom fields tags to WordPress permastructure settings
After you found and identified the meta keys names, you can insert them as tags inside the permastructures for “Team” custom post type. The settings can be altered in “Permastructures” section of the Permalink Manager’s dashboard (“Tools -> Permalink Manager -> Permastructures“).
As a result the new single pages/posts permalinks will automatically use the updated permastructure settings. To apply them to the old permalinks as well, please follow the instructions explained furtherly in the next step.
Reset old permalinks
Accordingly, after you save the permastructure settings, the custom fields values will be automatically inserted only to new posts and terms permalinks. If you would like to add custom fields values also to old WordPress permalinks, you will need to regenerate their permalinks using “Regenerate/reset” tool available in “Tools -> Permalink Manger -> Tools” section. Full instructions on how to reset them are posted here.
How to automatically update the WordPress permalinks after you update the custom field value?
Consequently, after you create a new post with some custom fields, Permalink Manager will use the default URI (with custom fields values inserted) as a custom permalink.
Please also bear in mind, that if you would like to automatically update the actual permalink after you save or update the post when and you change the custom field value, you will need to enable “Auto-update the URI” mode. Certainly, you can activate it manually for each post or set globally for all posts using Permalink Manager settings. Here you can find more info on how to enable this.
Obviously, it is also possible to manually change the permalinks and overwrite the default URI for particular posts.