Creating a Second Language Section in WordPress
Let’s face it: automated translation software just does not cut it. So what if I want to translate my English-based WordPress website into Spanish or another language?
This can be done with a little bit of template editing and some unique pages. The suggestions below will help you establish an alternative navigation menu, display an alternative header, and create content with a unique template. All of these steps are supported with the latest WordPress (3.x) so no plugin necessary!
Create some new pages.
Testing your new section will be much easier if you have some pages to populate the menu first. Create at least one page in your language. Be careful not to use accents or other special characters in the url (if you have one in the title you will need to edit the url). The url structure should be basic letters and dashes to prevent breaking the ability to view that page. You can Publish these new pages, assuming you did not include them in the menu of your live website (English version) – so they are still behind the scenes for now.
Make a new menu.
Under Appearance > Menus, you should have a listing of your current menus. Click on the “add” tab (a plus sign) to create a new menu for your language section. In my case, I will call it menu Spanish.
Add the pages you created earlier to this menu and Save the changes.
Now, we need to find out the menu id number. An easy way to do this is to click the tab for your menu and notice the url in the top, which will end in an id number like this:
wp-admin/nav-menus.php?action=edit&menu=71
So, my menu id is 71. Jot this number down for reference.
Create a new header file.
In your wp-content folder, you should have a standard file header.php. I am assuming you have a basic understanding of the file structure of a typical WordPress website. Make a copy of this file named appropriately for your section, such as header-spanish.php. Now make some small edits to the file to replace English words with your language (maybe a slogan or other text displayed in this header).
Toward the end of this file, there is probably a reference to your navigation menu. For example it might look like this:
<?php wp_nav_menu( array( ‘container’ => ”,’menu_id’=>’suckerfishnav’, ‘menu_class’ => ‘sf-menu sf-js-enabled’, ‘menu’ => ‘menu’, ) ); ?>
This one is a little more elaborate because I added some dropdown menus and classes. At the end, notice it just has ‘menu’ as the identifier. WordPress looks for the first, default menu. Change this value to your id number instead. So my line in the new header file becomes:
<?php wp_nav_menu( array( ‘container’ => ”,’menu_id’=>’suckerfishnav’, ‘menu_class’ => ‘sf-menu sf-js-enabled’, ‘menu’ => ’71′, ) ); ?>
Save and upload your header file to the server.
Create a page template.
Make a copy of your default page.php file. Put a template name in the heading of this file.
In the top of this file, you should notice a line to include the default header. The parenthesis within it are blank. Include the name of your new header file, enclosed in single quotes inside this parenthesis, such as:
<? get_header(‘spanish’);?>
You might decide to change other things in your page template, but this will at least include your custom header (along with the custom menu) into this layout.
Assign your template to the page.
Now go back and edit your pages for this special language section, and update the Template to your new custom template. You should see the name of it in the dropdown choices. Update/Publish the page to reflect this change. The next time you preview the page, you should see your updated header information and your translated menu loading instead of the default.
And lastly, once all your pages and menu items are complete and your new section is satisfactory, add some links to it on your main index page or your default menu so your visitors will be able to locate it.
See the Installation Guide under “Example of config.yml File” for an illustration of a UI map area declaration. Please note, just before your first run, research for the ‘YOUR CREDENTIALS’ string inside details folder and update that value with your account credentials.