Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Interesting objective. The url is actually created based on the page slug, which is singular ... so there's no easy way pair <code>/users/</code> with <code>/utilisateurs/</code>. Or at least not a native way.</p> <p>The best thing you can do is hook in to WordPress' url redirection methods and search a manually-configured array of English=>French page slugs.</p> <p>Just off the top of my head, <code>generate_rewrite_rules</code> might be a good action hook to look at for starters.</p> <p>Another possibility is to hook into the <code>query_vars</code> filter and manually replace any French page slugs with their English equivalents. Then your French URL should query the WordPress database for the exact same page as the English URL. You'll just need to be sure that the English slug exists in the database, or you'll run into problems.</p> <hr> <p><em><strong>Untested</em> Example</strong></p> <p>The trick is to hook into WordPress' query system and dynamically replace parts of the query as you go. So let's say you start with an array like this (I only have the one element because I don't speak French):</p> <pre><code>$translations = array( 'utilisateurs' =&gt; 'users' ); </code></pre> <p>Now we need a function that will take in a French string and return its English equivalent:</p> <pre><code>function translate_slug( $french ) { if( in_array( $french, array_keys( $translations ) ) { return $translations[$french]; } return $french } </code></pre> <p>Next, we hook onto the <code>query_vars</code> filter and replace our page slug variables with the desired English equivalents:</p> <pre><code>function filter_french_slugs() { global $wp_query; $wp_query-&gt;query_vars['pagename'] = translate_slug( $wp_query-&gt;query_vars['pagename'] ); $wp_query-&gt;query_vars['name'] = translate_slug( $wp_query-&gt;query_vars['name'] ); } add_filter( 'pre_get_posts', 'filter_french_slugs' ); </code></pre> <p>This should convert things over for you, but as I said above it's <em>untested</em> as of yet ... just an idea of how you could potentially pull this off.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload