Skip Navigation

[Resolved] Add custom permalink structure for custom post type

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user would like to have a custom permalink structure for a custom post type.

https://example.com/course/lesson/post-slug

Instead of:

https://example.com/lesson/post-slug

Solution:
This can be configured at the post-type definition. Check this screenshot http://prntscr.com/139aoyt
Then, you will need to save the permalink structure twice to purge WordPress rewrite rules. Go to Settings->Permalinks and just save the page twice.

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by diegoQ-2 3 years, 8 months ago.

Assisted by: Jamal.

Author
Posts
#2064543

Hello guys, I hope you are doing well.
I have a site that has two post types for "online course" and "in-person course" I want them both to use the permalink structure as:
hidden link
For instance, I want to change:
From: hidden link
To: hidden link
or
From: hidden link
To: hidden link
or
From: hidden link
To: hidden link

Notes:
+ "oferta-academica" is currently a normal page (hidden link)
+ after %post_type_slug% I want the structure to be the same as now. So basically, I want to add the "oferta-academica" segment before the current structure and change nothing else.
+ the "online course" post type is a LearnDash post type, while the "in-person course" is a toolset custom post type.

Please note I have researched and found a couple of posts suggesting an "add_permastruct" snippet (https://wordpress.stackexchange.com/questions/216337/change-permalink-structure-for-custom-post-type), but I'm unable to understand how to accomplish my need.

Finally, I would like this structure to be reflected in the breadcrumb. Thanks as always for your great support.

#2064955

Hello and thank you for contacting the Toolset support.

The suggested solutions on that StackExchange thread is based on custom code that should be added to a theme's file, a plugin, or using a 3rd party plugin such as Code Snippets. https://wordpress.org/plugins/code-snippets/

Toolset also offers a way to add custom code to your website. Check this article https://toolset.com/documentation/adding-custom-code/

However, you won't need to use any custom code for this target permalink structure, especially, because you are using Toolset :-).

Just update the custom post type definition to add a rewrite rule. Check this screenshot hidden link
Then, you will need to save the permalink structure twice to purge WordPress rewrite rules. Go to Settings->Permalinks and just save the page twice.

Check an example post's URL here hidden link
You can login to my test site using this one-click-login link hidden link
As you can see, I also created a page with the slug /offers/

Regarding the breadcrumbs, I can't really tell. The breadcrumbs are not a default WordPress or Toolset feature. It is usually a theme's or plugin's feature. Depending on what provides it on your website, the solution may be different.

I hope this helps. Let me know if you have any questions.

#2065267

Jamal, thank you for the reply. It provided a better understanding of how to accomplish my goal.
However, something is not quite working well.
I managed to change the permalink structure for the "curso-presencial" as you pointed out. The actual post types' posts are working, but the "archive" page is not working. I noted it is not working in your demo eighter.
My new working link:
hidden link
New Archive page not working (404):
hidden link
IMPORTANT: the previous archive worked just fine: hidden link

Any idea?

Regarding the breadcrumbs, it is not working, but I will ask the YOAST support team, as they are the best to answer.

FYI, I also did a similar change on the taxonomies I created, and it is working perfectly.

#2065439

Thank you for your feedback.

Regarding the 404 error on the post type archive page, it turned out to be caused by the first "/" in the rewrite slug. I used "offers/course" instead of "/offers/course" and then saved the permalinks twice, and it worked on my test site. Check this screenshot hidden link
The post type archive is now working correctly hidden link

Regarding the breadcrumbs, I totally agree, the Yoast team is the best one to answer your question. If it will our help too, let me know.

#2065931

It worked like a charm. Thanks for the help. My issue is resolved now. Thank you!