Fixing Custom Post Type Permalink and 404 Issues in WordPress
Content
Custom Post Type UI is a powerful tool for creating custom content types in WordPress. However, one of the most common areas where users encounter problems is with permalinks and URL structure. Issues range from 404 errors and unwanted URL prefixes to conflicts with other plugins. This guide will help you understand why these problems occur and how to resolve them.
Common Permalink Issues and Their Causes
Based on community reports, here are the most frequent permalink-related problems:
- 404 Errors on Single Posts or Archives: This often happens after changing a post type's slug, enabling Multisite, or when a page exists with the same slug as your custom post type.
- Unwanted /blog/ Prefix: CPT URLs suddenly include
/blog/in the structure (e.g.,site.com/blog/cpt/post-name). - Incorrect Hierarchy or Slug Conflict: A post type's single post redirects to a post from a different post type, or media file URLs conflict with CPT URLs.
- Custom Rewrite Rules Not Working: Attempts to create complex permalink structures or remove the post type slug entirely result in broken links.
How to Troubleshoot and Fix Permalink Issues
1. Always Flush Your Permalinks
The first and most crucial step for almost any permalink issue is to flush WordPress's rewrite rules. This regenerates the internal mapping of URLs to content. You can do this by visiting Settings > Permalinks in your WordPress admin and simply clicking "Save Changes" without making any modifications.
2. Check the 'With Front' Rewrite Setting
If your CPT URLs have a unexpected /blog/ prefix, the "With Front" setting is likely the culprit. This setting determines if the front of the permalink structure (like /blog/) should be prepended to your post type's permalink.
- To remove the
/blog/prefix, edit your custom post type in CPT UI and set the "With Front" parameter tofalse. - To keep the prefix, ensure it is set to
true.
3. Avoid Naming Conflicts
WordPress cannot have two different pieces of content with the same URL slug. A common cause of 404 errors is having a Page with the same slug as your custom post type or its archive. For example, if you have a page called "Locations" and a CPT also with the slug "locations," they will conflict. Rename either the page or the CPT slug to resolve this.
4. Understand the Limits of CPT UI
It's important to understand that the Custom Post Type UI plugin primarily handles the registration of post types and taxonomies. While it provides basic rewrite slug options, it cannot handle highly complex or nested permalink structures on its own (e.g., website.com/posttype1/category/country/city/posttitle). Achieving such structures requires custom code using WordPress's Rewrite API.
5. Investigate Plugin and Theme Conflicts
Sometimes, other plugins or your theme can interfere with rewrite rules. As seen in the threads, activating WooCommerce or a Multisite network can sometimes break previously working CPT URLs. A good troubleshooting step is to:
- Temporarily switch to a default WordPress theme (like Twenty Twenty-Four).
- Deactivate all other plugins except CPT UI.
- Check if the permalinks work correctly.
- If they do, reactivate your plugins one by one to identify the one causing the conflict.
6. Use Custom Code for Advanced Structures
For needs beyond CPT UI's settings, such as completely removing the post type slug from permalinks, you will need to add custom code to your theme's functions.php file. The provided code snippets in the community threads show that this involves two main filters:
post_type_link: To alter the generated permalink string.pre_get_posts: To adjust the main query so WordPress can still find the post without its CPT slug in the URL.
Warning: Always use a child theme when adding custom code and test changes on a staging site first, as incorrect rewrite rules can break your site's navigation.
Conclusion
Most Custom Post Type UI permalink issues can be resolved by flushing rewrite rules and carefully reviewing the "With Front" and rewrite slug settings. For more complex problems, check for naming conflicts and plugin incompatibilities. Remember that highly custom URL structures will require development work beyond the plugin's interface. The WordPress community and Codex are excellent resources for finding and understanding the necessary code snippets for advanced customization.
Related Support Threads Support
-
CPT UI Category URLhttps://wordpress.org/support/topic/cpt-ui-category-url/
-
Permalink basis set to false but cpt title is still in permalinkhttps://wordpress.org/support/topic/permalink-basis-set-to-false-but-cpt-title-is-still-in-permalink/
-
Archive title disappeared at CPThttps://wordpress.org/support/topic/archive-title-disappeared-at-cpt/
-
Renamed Post type, error in canonical URLhttps://wordpress.org/support/topic/renamed-post-type-error-in-canonical-url/
-
CPT UI and URLhttps://wordpress.org/support/topic/cpt-ui-and-url/
-
Delete / Remove CPThttps://wordpress.org/support/topic/delete-remove-cpt/
-
Migrated from old CP plugin into CPT UIhttps://wordpress.org/support/topic/migrated-from-old-cp-plugin-into-cpt-ui/
-
/blog/ added to CPT URLshttps://wordpress.org/support/topic/blog-added-to-cpt-urls/
-
website is broken to 404er after changing Benutzerdefinierte Rewrite-Titelformhttps://wordpress.org/support/topic/website-is-broken-to-404er-after-changing-benutzerdefinierte-rewrite-titelform/
-
CPT URL is leading back to the main post archive??https://wordpress.org/support/topic/cpt-url-is-leading-back-to-the-main-post-archive/
-
CPT URL 404 Errorhttps://wordpress.org/support/topic/cpt-url-404-error/
-
Permalink for CPThttps://wordpress.org/support/topic/permalink-for-cpt/
-
Change URL of custom post typehttps://wordpress.org/support/topic/change-url-of-custom-post-type/
-
Portfolio items do not displayhttps://wordpress.org/support/topic/portfolio-items-do-not-display/
-
CPT permalink for Child page?https://wordpress.org/support/topic/cpt-permalink-for-child-page/
-
Permalinks don’t show up correctly for one CPThttps://wordpress.org/support/topic/permalinks-dont-show-up-correctly-for-one-cpt/
-
CPT slug (/listing) redirecting to slug for another post type (/venue)https://wordpress.org/support/topic/cpt-slug-listing-redirecting-to-slug-for-another-post-type-venue/
-
Categories for the CPT UI Post Type replaced Categories for another pluginhttps://wordpress.org/support/topic/categories-for-the-cpt-ui-post-type-replaced-categories-for-another-plugin/
-
Custom post type with a post from a different custom post typehttps://wordpress.org/support/topic/custom-post-type-with-a-post-from-a-different-custom-post-type/
-
category permalink showing post type namehttps://wordpress.org/support/topic/category-permalink-showing-post-type-name/
-
CPT + ACF Permalinkhttps://wordpress.org/support/topic/cpt-acf-permalink/
-
Custom permalink suddenly stopped workinghttps://wordpress.org/support/topic/custom-permalink-suddenly-stopped-working/
-
different permalinks structure for different post type ?https://wordpress.org/support/topic/different-permalinks-structure-for-different-post-type/
-
CPT + ACF Permalinkhttps://wordpress.org/support/topic/cpt-acf-permalink-2/
-
Categories pagination not working after migration to a CPThttps://wordpress.org/support/topic/categories-pagination-not-working-after-migration-to-a-cpt/
-
CPT URL Structurehttps://wordpress.org/support/topic/cpt-url-structure/
-
URL category / breadcrumbshttps://wordpress.org/support/topic/url-category-breadcrumbs/
-
edit permalinkshttps://wordpress.org/support/topic/edit-permalinks-2/
-
Conflict with blog post categorieshttps://wordpress.org/support/topic/conflict-with-blog-post-categories/
-
Changing the URL structure doesn’t workhttps://wordpress.org/support/topic/changing-the-url-structure-doesnt-work/
-
WooCommerce Cuts Off CPThttps://wordpress.org/support/topic/woocommerce-cuts-off-cpt/
-
Post categories are not the same as those in the databasehttps://wordpress.org/support/topic/post-categories-are-not-the-same-as-those-in-the-database/
-
Post URL changing with category changes/additionshttps://wordpress.org/support/topic/post-url-changing-with-category-changes-additions/
-
Image Titles conflict with CPT Permalinkhttps://wordpress.org/support/topic/image-titles-conflict-with-cpt-permalink/
-
custom portfolio CTAhttps://wordpress.org/support/topic/custom-portfolio-cta/
-
CPT Archive page > 404 since turning on MUhttps://wordpress.org/support/topic/cpt-archive-page-404-since-turning-on-mu-2/