hreflang how to implement?

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
tamimh
Rank 0 - Newcomer
Posts: 1
Joined: Sat Feb 13, 2016 2:12 am

hreflang how to implement?

Post by tamimh »

Hi
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 http://cbutterworth.com/simple-php-script-adding-hreflang-tag/ from Chris. so I added it to my header.php like this:

Code: Select all

<link rel=”alternate” href=”https://www.mysite.com<?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 http://www.technicalseo.info/seo-tools/hreflang/ and I get "Default language tag not existing (en)"

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

10x
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX

Re: hreflang how to implement?

Post by Albert Wiersch »

Hello,

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

<html>
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!
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial