[wp-hackers] Best way to allow slug rewrite of CPT via i18n

Nikola Nikolov nikolov.tmw at gmail.com
Tue Nov 26 21:59:23 UTC 2013


Just a warning here, consider the following situation:

 - Multilingual site(whichever plugin).
 - Multiple languages, each with it's own translation file(therefore each
one declaring it's own slug for your post type).
 - The user regenerates the permalinks by going to Settings > Permalinks.
Only the permalinks with the currently active language's slug are
regenerated. All translation permalinks are not.
 - You go to the front-end and visit the site in a different language. Your
links now use the correct slug for that language, but they end-up in 404's.

I know that ultimately it's great to be able to have different slugs for
each language, but it's really difficult to do so.

A different approach that I can suggest is to use a plugin option to set
the slug(from a settings page). This way, the slug can still be changed and
if anyone else is trying to create multiple rewrite rules for your
plugin(for each language for instance), they are still able to do so.

While working on my own multilingual plugin, I came across that situation -
I wanted to let the user define a unique slug for each language - in the
end it mostly worked, but with a lot of hacking.

So, my advice is - make the slug dynamic via a plugin option and that's it.


On Tue, Nov 26, 2013 at 11:52 PM, Nicholas Ciske <nl at thoughtrefinery.com>wrote:

>
> You probably want to run it through sanitize_title before you attempt to
> use it... lest a wily translator blow up your permalinks ;-)
>
> http://codex.wordpress.org/Function_Reference/sanitize_title
> _________________________
> Nick Ciske
> http://thoughtrefinery.com/
> @nciske
>
> On Nov 26, 2013, at 3:48 PM, Tom Barrett wrote:
>
> > Hello
> >
> > What is the best way to allow the of a custom post type to change via
> > translation.
> >
> > I'm currently doing this:
> >   'rewrite'  => array( 'slug' => __( 'glossary', WPG_TEXTDOMAIN ) ),
> >
> > Is that good?
> >
> > Thanks!
> > --
> > http://www.tcbarrett.com | http://gplus.to/tcbarrett |
> > http://twitter.com/tcbarrett
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list