Skip to content

setLinkRel(string rel,string url,array additionalAttributes = [])

The setLinkRel method is used to set links in MetaProperties object.

This method only works in integration modules.

Input parameters

rel

string, allowed values:

  • canonical
  • dns-prefetch
  • preconnect
  • preload
  • alternate
  • prev
  • next
  • author
  • publisher

For the following rel values:

  • canonical
  • prev
  • next
  • publisher

only one <link> tag with a given rel value will be displayed. This means that if the setLinkRel method is called multiple times with the same rel value, only the last set link will be displayed. Previous ones will be overwritten.

url

string The URL address for the link. You can use absolute or relative URLs.

additionalAttributes

array Additional list of attributes to be added to the <link> tag.

Returned value

A returned value has a type of bool. true is returned if the link was set successfully, otherwise false.

Example

source
{{ ObjectApi.setLinkRel("canonical", "https://www.shoper.pl") }}
{{ ObjectApi.setLinkRel("dns-prefetch", "https://fonts.gstatic.com") }}
{{ ObjectApi.setLinkRel("preconnect", "https://fonts.gstatic.com", ["crossorigin"]) }}
{{ ObjectApi.setLinkRel("alternate", "/pl_PL", {"hreflang":"pl"}) }}
output
<link rel="canonical" href="https://www.shoper.pl" />
<link rel="dns-prefetch" href="https://fonts.gstatic.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link rel="alternate" href="https://www.shoper.pl/pl_PL" hreflang="pl" />