XF 1.5 I'm looking for the current URL variable?

MstrfBlng

Active member
#1
I want to add a hreflang tag to all pages. And If I'm correct I can add this to the PAGE_CONTAINER template.

I want to add this to every page. Where "nl" is not a variable, but everwhere the same.

Where %URL% must be the canonical URL of the page:

<link rel="alternate" hreflang="nl" href="%URL%">

So for example:

For this page:

https://forum.website.com/threads/weer-een-nieuwe.18310/

It must be:

<link rel="alternate" hreflang="nl" href="https://forum.website.com/threads/weer-een-nieuwe.18310/">

And for this page:

https://forum.website.com/forums/glas-rubber-en-kunststof.24/

It must be:

<link rel="alternate" hreflang="nl" href="https://forum.website.com/forums/glas-rubber-en-kunststof.24/">

And so on :)

How do I do that?

Thanks,

Tim
 

MstrfBlng

Active member
#3
Yes! Finally! Thank you @Brogan!

I implemented it and it works.

For others who like to have this to, like @Fred.

Add this to the PAGE_CONTAINER template in the section <xen:hook name="page_container_head">:

Code:
<link rel="alternate" hreflang="nl" href="https://forum.website.com{$requestPaths.requestUri}">
Just before the </xen:hook>

Where "nl" should be replaced by your forum language of course and the 'forum.website.com' for your URL.
 

Fred.

Well-known member
#5
I have done something like that before, but it still doesn't solve my problem as far as I understand because most of my forum is in Dutch, but my link directory is in English.
Is it possible to specify where to use Dutch and where to use English?
 

Brogan

XenForo moderator
Staff member
#6
You should be able to use xen:container in the relevant template(s) to set the value in the PAGE_CONTAINER template.
 

Fred.

Well-known member
#7
You should be able to use xen:container in the relevant template(s) to set the value in the PAGE_CONTAINER template.
I'm not good with this o_O :coffee: Not sure how I can do that. If possible can you give me an example?

let's say https://example.com/english/ has hreflang="en-US"
and https://example.com/ has hreflang="nl-BE"

The other thing I'm asking myself at the moment is what if you serve more than two countries that have the same language but other hreflang codes? Just use the language and not specify the country? Like this hreflang="nl" or should I use multiple hreflang tags and specify the country?
 

Brogan

XenForo moderator
Staff member
#8
If possible can you give me an example?
Here's an example of how you would change it for the forum index and forum view.

Add this to the PAGE_CONTAINER template:
Code:
<link rel="alternate" hreflang="{$lang}" href="{$requestPaths.fullUri}">
With that line of code you are defining hreflang as the {$lang} variable.


Then in the templates you set the value for the variable by adding a line to each template where you want to define it.

For example, to set it to nl-BE for the forum index, add this to the forum_list template:
Code:
<xen:container var="$lang">nl-BE</xen:container>

To set it to en-US for individual forums, add this to the forum_view template:
Code:
<xen:container var="$lang">en-US</xen:container>
 

Fred.

Well-known member
#9
Here's an example of how you would change it for the forum index and forum view.

Add this to the PAGE_CONTAINER template:
Code:
<link rel="alternate" hreflang="{$lang}" href="{$requestPaths.fullUri}">
With that line of code you are defining hreflang as the {$lang} variable.


Then in the templates you set the value for the variable by adding a line to each template where you want to define it.

For example, to set it to nl-BE for the forum index, add this to the forum_list template:
Code:
<xen:container var="$lang">nl-BE</xen:container>

To set it to en-US for individual forums, add this to the forum_view template:
Code:
<xen:container var="$lang">en-US</xen:container>
Thank you for the extended and well documented example Brogan. (y)
Now I understand it and I was able to implement it correctly. :cool:
 
Top