Spring Sale! Save 30% on all books w/ code: PLANET24
Web Dev + WordPress + Security

Valid, SEO-Friendly Post Translation Links

Ever wanted to provide automatic language translations of your web pages without installing another plugin? Here is a valid, SEO-friendly technique that takes advantage of Google’s free translation service. All you need is a PHP-enabled server and you’re good to go. Just copy and paste the following code into the desired location in your page template and enjoy the results. Once in place, this code will produce translation links for eight common languages for every page on your site. Grab, gulp and go:

<ul id="translations">
	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Cde" rel="nofollow">Translate this page to Deutsch</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Ces" rel="nofollow">Translate this page to Espanol</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Cfr" rel="nofollow">Translate this page to Francais</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Cit" rel="nofollow">Translate this page to Italiano</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Cpt" rel="nofollow">Translate this page to Portugues</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Car" rel="nofollow">Translate this page to Arabic</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Cja" rel="nofollow">Translate this page to Japanese</a></li>

	<li><a href="http://translate.google.com/translate?u=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); ?>&langpair=en%7Cko" rel="nofollow">Translate this page to Korean</a></li>
</ul>

As formatted, this code will generate an unordered list of translation links. You may change this formatting or even style the links with their associated country flags using a little CSS. When used on blogs, this code will enable users to translate posts on the fly via automatic generation of the required URL parameter. Further, each page URL is encoded within the query string to ensure complete markup validation. Finally, this code even goes the extra mile by including nofollow attributes in each link, thereby preventing valuable link juice from needlessly leaking to the Google translation machine.

About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
Wizard’s SQL for WordPress: Over 300+ recipes! Check the Demo »
Comments are closed for this post. Something to add? Let me know.
Welcome
Perishable Press is operated by Jeff Starr, a professional web developer and book author with two decades of experience. Here you will find posts about web development, WordPress, security, and more »
USP Pro: Unlimited front-end forms for user-submitted posts and more.
Thoughts
I live right next door to the absolute loudest car in town. And the owner loves to drive it.
8G Firewall now out of beta testing, ready for use on production sites.
It's all about that ad revenue baby.
Note to self: encrypting 500 GB of data on my iMac takes around 8 hours.
Getting back into things after a bit of a break. Currently 7° F outside. Chillz.
2024 is going to make 2020 look like a vacation. Prepare accordingly.
First snow of the year :)
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.