Manipulate Permalink

I’m using WPML to translate a website. The only major issue I have with WPML is that you cannot have a page in different languages with the same slug.

Therefore www.example.com/contact/ and www.example.com/fr/contact/ is not possible.

Read More

To get around this I was thinking of saving the french version as www.example.com/fr/contact-fr/ in the database but have this transparent to the user. To do that I was thinking of manipulating the URL so the the user sees www.example.com/fr/contact/ but WordPress handles it as if the page were www.example.com/fr/contact-fr/

Is it possible to do this with a function or rewrites?

Related posts

Leave a Reply

3 comments

  1. I don’t know how WPML impacts the handling of the rewrite rules, but it should be possible to create a rewrite rule that constructs the pagename from two different parts of the rewrite pattern. From the top of my head:

    add_rewrite_rule('(..)/(.+)', 'index.php?pagename=$matches[2]-$matches[1]');
    

    If you are going to do avanced stuff with rewrite rules you might want to install my Rewrite Analyzer plugin to try stuff out.

  2. It will be easier to become a bit more creative with titles/slugs.

    Also keep in mind that title and slug do not necessarily need to be the same.

    So the title of the French contact page can still be “Contact” and then the slug can become “contactez-nous”.