Add custom fields to WordPress permalinks

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.

All of the URLs below have been purposefully simplified to provide you a basic understanding of this feature. Please also notice that the names of custom post types and custom fields in this article are just examples. In your particular scenario, their names may be entirely different.

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). You have complete control over the permastructure settings and may add custom fields in any way you choose. It will also function in more complicated cases; the structure shown below is only an example.

Some of the functionalities presented in this article are not available in free version (Permalink Manager Lite). Buy Permalink Manager Pro

Let is say you want to add a location and department name to the permalinks of our team members single pages to indicate where each of your workers works. One alternative is to establish a new hierarchical taxonomy and attach its multi-level slug to the URL of a single team member page.

https://example.com/team/john-doe/

https://example.com/team/%__country%/%__city%/%__department%/john-doe/

https://example.com/team/norway/oslo/management/john-doe/

Permalink Manager provides a another, more straightforward option. You may use the plugin to automatically add custom fields to permalinks instead of registering a custom taxonomy.

How to add SKU to product permalinks?
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.

Instructions

The custom field permastructure tags should be structured as follows: %__custom_field_key%.

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

How to display Custom Fields container in WordPress admin panel?

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 custom fields table in WordPress editor.
The custom fields table will be shown somewhere below the main content editor once you enable the “Custom Fields” metabox.

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.

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

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.

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
Permalink Manager will replace the “Relationship“, “Post Object“, or “Taxonomy” field in a permastructure tag with the slug of the specified post/term item if you use it in a permastructure tag.

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.

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

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.

Post Field Groups in Toolset

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.

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

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:

Where you can find the custom fields' names in JetEngine?

In this example, the permastructure tag will be: %__country% (%__name_of_the_field%).

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

Wordpress permalink structure settings with custom field values.
Permastructure settings for “Team” custom post type.
By default, custom fields will only be added to the new posts or terms permalinks.
If you want to add custom field values to previously existing WordPress URLs, you must regenerate them using the “Regenerate/reset” tool. To locate it, go to the “Tools -> Permalink Manager -> Tools” section. Please see this page for detailed instructions on how to use it.

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.

Auto-update "Current URI" field in URI Editor

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.

A sample WordPress permalink with custom fields manually adjusted.

Go up