Save up to 25% on pro security plugins w/ our Security Bundle »
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.

Jeff Starr
About the Author
Jeff Starr = Web Developer. Security Specialist. WordPress Buff.
WP Themes In Depth: Build and sell awesome WordPress themes.
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 »
Digging Into WordPress: Take your WordPress skills to the next level.
Thoughts
Fall season almost here :)
My greatest skill on social media is the ability to simply ignore 98% and keep scrolling without interacting.
Enjoying this summer, getting some great positive energy. Refreshing and inspiring.
☀️ Pro plugin giveaway! Enter to win 1 of 4 lifetime licenses for our WordPress security plugins, including 10-site Security Bundle!
There is no end to what humans can achieve when they work together.
Excellent (and free) tool to test your site's SSL configuration.
Plugin updates! All of our free and pro plugins ready for WordPress 6.2.
Newsletter
Get news, updates, deals & tips via email.
Email kept private. Easy unsubscribe anytime.