When using a WordPress qTranslate-X plugin on a website, you might also want to translate permalinks (also known as slugs). Currently, qTranslate-X doesn't support this feature, but we can use other WordPress plugin named qTranslate Slug that does exactly that. In this article, we will explore the widget and the settings available for qTranslate Slug. Finally, we will examine, how to use it.
The qTranslate Slug plugin is an add-on for mQtranslate and qTranslate, both of which are now deprecated in favor of qTranslate-X plugin. With this add-on, we can translate permalinks (slugs) for posts & pages.
Let's examine this addon in a little more detail.
qTranslate Slug Settings
We can find settings for qTranslate Slug by going to Dashbord > Settings > Slug options.
There, we have the options to:
- Add translations to tags and categories taxonomies:
- Add translations to custom registered post types:
Click to Enlarge In the above screenshot, the post type named books has been registered (using the code below), so the translation fields are available for it. For more information about registering post types, check the Codex page for register_post_type function.
The basic code example of registering books post type is as follows:
function codex_custom_init() { $args = array( 'public' => true, 'label' => 'Books' ); register_post_type( 'book', $args ); } add_action( 'init', 'codex_custom_init' );
When no post types are registered, the post type option in the settings will contain no fields.
- Change the way how the CSS styles for the qTranslate Slug "Flag Switcher Widget" are added.
Click to Enlarge If you are already using qTranslate-X Flag switcher, we don't need these styles and can turn them off by choosing the last radio button none.
qTranslate Slug Widget
This addon also has its own widget Language selector (QTS) for displaying the Flag menu:
The widget is very similar to the one from qTranslate-X, except it doesn't have the option for custom list format, so I prefer to use the qTranslate-X widget instead.
And now finally, let's explore, how to use the qTranslate Slug add-on.
Translating permalink (slugs) for each language in Posts and Pages
When editing a post or page, we will have an option named “Slug QTS” where we specify the permalink of the edited post / page for each language that is enabled by qTranslate-X:
For example, in the contact page, we would put these values:
When English language is selected, we would get the following URL:
www.mysite.com/en/contact
And for German language we get this:
www.mysite.com/de/kontakt
And this is it. The permalinks will get translated to the currently selected language, so we are done.
They also get translated, when we have hard-coded links in our template. For example, if our contact page has page id of 12, the following code inside a template will display the contact link and it will get translated to the currently selected language:
<a href="<?php echo esc_url(get_permalink(12))."\">".get_the_title(12) ?></a>
Conclusion
With qTranslate Slug plugin add-on for qTranslate-X, we have the ability to translate permalinks / slugs for pages and posts in our multi-language website. In this article, we explored the various settings and widget and then we looked into how to use the add-on.
Kyle
October 8, 2019Thank you for informations.