1. Home
  2. Docs
  3. Features
  4. How to easily add the custom fields to the permalinks?

How to easily add the custom fields to the permalinks?

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.

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

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.

A sample WordPress permalink with custom field values.
The new permalink contains the custom fields values set-up with Advanced Custom fields.

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.

Advanced Custom Fields names to be used in WordPress permalinks

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
If you use “Relationship”, “Post object” or “Taxonomy” as a custom field tag, Permalink Manager will use the slug of selected post/term item.

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:

Toolset Types custom fields in WordPress permalinks
Toolset Types custom fields in WordPress permalinks

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:

Sample Toolset Types custom field that can be used in WordPress permalinks

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%

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“).

Wordpress permalink structure settings with custom field values.
Permastructure settings for “Team” custom post type.
The format of permastructure tags should be: %__custom_field_key%.

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.

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.

Automatically update WordPress permalinks with custom fields values

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.

A sample WordPress permalink with custom fields manually adjusted.

Was this article helpful to you? Yes No