Skip Navigation

[Resolved] Rewrite custom post type slug in permlimks and get it translated

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

Problem:

The issue here is that the user had a slug "vob-news" but wanted to rewrite this slug to only "news" on the frontend.

Solution:
We actually do provide some of these functions that the wordpress API offers. If you go to your post type settings at Toolset -> Post Type and edit your post type.

Under the Options accordion you'll be able to see all the options that are available.

There is a rewrite option that you can use. If you enable the rewrite option and provide and alternate slug here, then on the frontend that alternate slug will be used.

This support ticket is created 3 years, 10 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 6 replies, has 2 voices.

Last updated by mashaB 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#2109505

Tell us what you are trying to do?
I want to have internal custom post type slugs, but in permlinks URLS which are used externally to have an alias.

I like to add a prefix to slugs of my post types that way they won’t clash with any post types added by any third party plugins and I can distinguish my custom posts and taxonomies, but I don’t want the prefix to be made public.

For example:
Custom post slug is "vob-news" when registering a custom post with Toolset.
In URL slug I want to have another slug - "news".

Is there any documentation that you are following?
https://developer.wordpress.org/reference/functions/register_post_type/

'rewrite'
(bool|array) Triggers the handling of rewrites for this post type. To prevent rewrite, set to false. Defaults to true, using $post_type as slug. To specify rewrite rules, an array can be passed with any of these keys:
'slug'
(string) Customize the permastruct slug. Defaults to $post_type key.
#2109539

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Masha,

The rewrite rule is for wordpress internal processes to know what the slug of the custom post type is. This won't allow you to achieve your goal because this is in the defining of the custom post type where you set the slug.

My advise here is to continue using your "news" slug as this will also be better for SEO rather than prefixing the slug with another term.

Secondly if you want to prefix the slug and then add some rewrite rule for the 'news' slug then this will also have issues because if there is another plugin that uses the "news" slug then if you change the slug on the frontend you will get redirected to the plugin's post that uses the "news" slug.

Essentially it will cause some form of conflict and confusion in wordpress where it won't know exactly which post to display.

Please let me know if this helps.
Thanks,
Shane

#2109557

Hi Shane,

Thanks for your reply. But I got confused by it.

WP documentation (https://developer.wordpress.org/reference/functions/register_post_type/) says that rewrite function allows to change slug when creating permalink and this is what I try to achieve. It should not effect how the custom type is registered within WP in my understanding.

Also, I am not using "news", I am using "vob-news" and this is ok for internal use, but I do not like to expose it for external view, including SEO which is currently happening.

As Toolset should be using register_post_type() it should be compatible with parameters it provides when registering a new custom type within WP.

Regarding your second point, I think it can happen no matter if the slug is rewritten or not. I do not understand how rewriting can contribute here. But at least internally my slug will be distinct from the other plugin slug.

#2109573

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Masha,

I understand what you're saying, however the point i'm bringing across is that if there is another plugin that creates a post with the "news" slug and you're rewriting your "vob-news" slug to "news" on the frontend then wordpress won't know which post to display.

Example Woocommerce uses the slug "Product" if you create your post type "vob-product" and you rewrite the slug on the frontend to "product" then wordpress will assume that you're looking for a Woocommerce product.

Regarding your second point, I think it can happen no matter if the slug is rewritten or not. I do not understand how rewriting can contribute here. But at least internally my slug will be distinct from the other plugin slug.

Your slug will be unique internally but your posts won't display correctly on the frontend. If this is something you really want to achieve then it will require custom coding which is out of the scope of our support forum.

Thanks,
Shane

#2109593

Shane, so am I understanding it correctly that Toolset is limiting WP inbuilt functionality for custom post types by not allowing users to provide arguments for registering a post type via Tooset?

Again, this WP documentation lists available arguments and I am not asking to something beyond WP core features:
https://developer.wordpress.org/reference/functions/register_post_type/

Thanks!

#2109609

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Masha,

so am I understanding it correctly that Toolset is limiting WP inbuilt functionality for custom post types by not allowing users to provide arguments for registering a post type via Tooset?

We actually do provide some of these functions that the wordpress API offers. If you go to your post type settings at Toolset -> Post Type and edit your post type.

Under the Options accordion you'll be able to see all the options that are available.

There is a rewrite that I just test to ensure that its able to provide the functionality that you require. If you enable the rewrite option and provide and alternate slug here, then on the frontend that alternate slug will be used.

I must apologize for not bringing this option to your attention, however this should be able to resolve your issue without the use of any code.

If there are any further questions or clarification needed on this please let me know.
Thanks,
Shane

#2109869

My issue is resolved now. Thank you, Shane!