Relative Paths Issue
-
Hello,
I’m using your plugin to change languages on my site. One thing i noticed is that in the generated
<link>
tag it’s outputting a relative path instead of a fully qualified URL. The output looks something like this:<link rel="alternate" href="/?locale=es" hreflang="es">
Everything I’ve read and even the Yoast Article about hreflang suggests using fully qualified URLs instead of relative. Yoast suggests:
Regardless of your type of implementation, each URL needs return links to every other URL, and these links should point at the canonical versions…
Looking at the plugins code I’ve outlined the problem lines below. If we take a look at:
bablic/sdk.php LN 345 FN get_alt_tags()
bablic/sdk.php LN 365 FN alt_tags()We can see in these functions that the
$url
variable is set using theREQUEST_URI
which is not a URL at all but a path. It looks like this:$url = $_SERVER['REQUEST_URI'];
The function then goes on to pass this as a URL to
BablicSDK::get_link()
even though the$url
isn’t a URL at all.A fix for this could be to use
home_url()
instead. Something like this:$url = home_url( $_SERVER['REQUEST_URI'] );
The above line would give us the full URL and pass along any additional
REQUEST_URI
s as needed. This is an SEO change I would love to see in a future version so if you have any questions or if there’s anything else I can help with as far as testing please let me know!
- The topic ‘Relative Paths Issue’ is closed to new replies.