Page 1 of 1

hreflang how to implement?

Posted: Sat Feb 13, 2016 2:16 am
by tamimh
My new Wordpress website is for US users.
In search console >search traffic> International Targeting I get a message "Your site has no hreflang tags"
searching google, I came across this script from Chris. so I added it to my header.php like this:

Code: Select all

<link rel=”alternate” href=”<?php echo parse_url($_SERVER[‘REQUEST_URI’],PHP_URL_PATH); ?>” hreflang=”en-us” />
I am still getting the "Your site has no hreflang tags" message.
I tested with and I get "Default language tag not existing (en)"

Please drop some advice, my knowledge in scripting is limited.


Re: hreflang how to implement?

Posted: Wed Feb 17, 2016 11:30 am
by Albert Wiersch

Regarding the "Default language tag not existing (en)" message, it may refer to no "lang" attribute being used with the "html" element.

For example, try changing this:

Code: Select all

to this:

Code: Select all

<html lang="en">
Also, to confirm that there is an "hreflang" attribute now (due to your changes), I would view the page in a browser then pull up the HTML source and search for "hreflang" to make sure it's correct and it's where you expected it to be in the HTML source.

I hope this helps!