Custom Post Types Permalinks

Many websites use custom post types and taxonomies to make content management easier. Recipe websites are a prime example of this, with individual posts-recipes organized by taxonomies such as cuisine or ingredients.

When registering a custom post types, their permalinks have predefined formats that can be customized to a certain extent using the built-in tools. In terms of permalink customization, WordPress falls short. Therefore if you want more control, you will need to use additional plugins.

What are Custom Post Types?

The basic content types included with WordPress are pages and posts. WordPress includes two default content types: posts and pages. Sometimes the data does not fit into either of the built-in content types. If this is the case, you may declare a custom content types and separate the content from the standard posts and pages.

There are many situations when this may be useful. Custom post types may handle a variety of content types, including testimonials and events. They are also an essential component of the WooCommerce plugin, which uses them for products.

Declaring Custom Post Types

There are many methods to define a custom post type. The simplest way is to add a code snippet to your WordPress codebase. It is not that difficult, and you need to use the register_post_type() function.

function custom_post_type_registration() {
	 $args = array(
		 'public' => true,
		 'label' => 'Book',
		 'supports' => array('title', 'editor', 'thumbnail'),
		 'rewrite' => array('slug' => 'publication'),
	 );
	 register_post_type('book', $args);
}
add_action('init', 'custom_post_type_registration');
Not declaring the 'rewrite' arguments causes WordPress to use the custom post type's slug name, which in this case is "book".

How to Register a Custom Post Type Without Using PHP Code?

If you are not familiar with coding or are unsure how to write your own code snippet, a plugin is the most reliable option. There are lots of plugins you can use, like "Pods" or "ACF", that let you define additional custom fields. You can install them for free directly from admin dashboard.

Are Custom Post Types Always Necessary?

While there are many situations where unique post types can be advantageous, they are not necessarily essential. Consider a few things before using them.

  • Blogs
    First and foremost, for traditional blog websites, the built-in "post" type is more than enough. Categories and tags are sufficient for most blogging needs.
  • Simple websites
    If your website is one-pager or has only a few static pages, such as "about us" and "contact", adding any additional custom post type makes no sense.
  • Content that is alike in structure and form
    When you have a lot of similar content items, like "apartments for rent", CPTs make it easier to organize and manage them. A notable example of this is the "products" post type used in WooCommerce for online stores.

Custom Post Type Permalinks

One of the parameters you can pass to the register_post_type() function is the rewrite slug. To put it simply, it defines the basic structure of the custom post type's permalink.

When setting up the custom post types, users often overlook it. Understanding this is critical in order to avoid rewrite rules conflicts that might prevent WordPress from processing URLs correctly.

To make things clear, let us go back to the basic code from the previous section. The rewrite slug is specified as the 'slug' parameter under 'rewrite'. In that particular instance, it is set to 'publication'. Therefore, the custom post type's permalink structure will be as follows:

https://example.com/publication/post-title

Many developers try to remove the rewrite slug from custom post type permalinks by changing it to single slash "/", hence breaking the permalinks structure and causing unexpected "404 Not Found" errors.

Configuring Rewrite Slugs in ACF

One of the most well-known WordPress plugins is Advanced Custom Fields (ACF). When setting up custom post types with ACF, you can easily set the rewrite slug within the plugin interface.

Dynamic Permalinks with Advanced Custom Fields (ACF)

For further information on how to customize post type permalinks created with ACF, check out this article.

To access the "URL Slug" field, first turn on the "Advanced Configuration" toggle button. After enabling it, go to the "Permalink Rewrite" section and select the "Custom Permalink" option.

ACF permalink settings

What Is the Problem With the Default Custom Post Type Permalinks?

There are some problems that can come up with WordPress's default custom post type permalinks. They mostly have to do with URL structure and how it affects user experience and SEO.

Simply put, WordPress includes the rewrite slug as part of the URL structure. This can result in non-descriptive and lengthy URLs that are not user-friendly or optimized for search engines.

Rewrite slug in custom post type permalink
By default, you can only use the slug (anna-nowak), which is the last part of the URL. Rewrite slug "/team/" in the example above cannot be easily customized.

The default settings may not provide users with enough control over the structure of their custom post type permalinks. This is apparent if you want to use the same permalink format for more than one type of content.

Duplicate rewrite base in WordPress permalinks

There are situations when you may need more flexibility, such as reusing the same URL structure for multiple custom post types. In such a situation, WordPress's default settings might not be enough and then you have two options available.

If you know PHP, you may write a tailored code snippet or pay a WordPress developer to do it for you. You can also use an already-made solution, like the Permalink Manager plugin, which will save you time and money.

By using a tool like Permalink Manager, developers may adjust the URL structure for each custom post type without worrying about rewrite rules conflicts. This plugin provides a user-friendly interface for managing permalinks, offering a level of control that might be difficult to achieve with a code snippet.

One of the most useful and popular features of Permalink Manager Pro is the ability to edit individual permalinks within custom post types. This allows you to customize the URL structure of each post to meet specific SEO and readability requirements.

Edit individual custom post type permalink

The plugin lets you change each URL as a whole, unlike the WordPress permalink system, which only allows changes to the last slug.

Custom Fields in Custom Post Type Permalinks

Another feature not found in other tools is the ability to dynamically add custom fields to custom permalinks. Custom fields are extra pieces of information associated with a post, and incorporating them into permalinks may improve both SEO and UX.

Add custom fields to permalinks

This feature is especially helpful if you want to include dynamic content directly in the URL, like location, SKU number, etc.

Taxonomies are just as important for organizing content on your WordPress website as custom post types. Because taxonomies are connected to post types, you can use the Permalink Manager to easily add the linked taxonomy terms in the post type permalinks.

Edit individual custom post type permalink

By doing so, you can build a hierarchical URL structure that better indicates the relation between your content elements. It is a good starting point for SEO and improving the usability of your website.

by Maciej Bis

Leave a Reply

Your email address will not be published. Required fields are marked *