Is there a way to remove the slug from a custom post?

Is there a way to remove the slug from a custom post?

The following code will work, but you just have to keep in mind that conflicts can happen easily if the slug for your custom post type is the same as a page or post’s slug… First, we will remove the slug from the permalink: Just removing the slug isn’t enough.

Is it possible to create duplicate slugs in WordPress?

As WordPress doesn’t automatically prevent creating duplicate slugs across different post types, you may find problems accessing posts having the same post slugs because of losing uniqueness in CPT permalinks after removing the CPT slugs.

How to disable custom post type in WordPress?

Step 1: Disable rewrites on your custom post type by setting rewrites to ‘false’ when you register the post: Step 2: Manually add our custom rewrites to the bottom of the WordPress rewrites for our custom_post_type NOTE: Depending on your needs, you may want to modify the above rewrites (disable trackbacks? feeds?, etc).

Why are my CPT slugs not working in WordPress?

After solving the first part, your CPT permalinks don’t have CPT slugs anymore. But, now, the problem is WordPress doesn’t know how to find your posts from those new permalinks because all it knows is CPT permalinks have CPT slugs. So, without a CPT slug in the permalink, it can’t find your post.

When to redirect to new post slug in WordPress?

When you make a change to a post slug permalink after its been published, WordPress will automatically redirect it to the new post slug (doing a 301 redirect). This works well, but sometimes you want no existence of the old post slug. These SQL statements will help you cleanup your old post slugs.

Why does WordPress not display custom post type?

When I created a page with the slug “my-event” and an event (CPT) with the slug “my-event”, the custom post type is displayed. Any other pages do not work either. If you look at the picture above it becomes clear why: the custom post type rule will always match against a page slug.

How to remove the base slug in WordPress?

To remove the base slug, you can add another code snippet with the following ( gist ). You will need to update accordingly with your CPT name. Note: While the above works fine, and I’m using it on some of my sites, know that it might cause functionality issues with other plugins that rely on the full URL being there.

Why do I need a slug in WordPress?

Because WordPress has no way of identifying if it’s a page or a custom post type that does not exist, it will return 404. That’s why you need a slug to identify either the page or CPT. A possible solution would be to intercept the error and look for a page that might exist similar to this answer.

What can a custom post type be used for?

From press releases to case studies, or even a database of artists. Custom post types can be used for all sorts of different things. One of the problems though is they aren’t always the easiest thing to set up.