Sets the page's SEO-related link tags.
Use the setLinks()
function to set a page's SEO-related link tags which provide additional
SEO information about your page. For example, you can set a link to a canonical
or alternate version of the current page.
The links you set overwrite any link information set earlier.
Notes:
You should always set the links inside the onReady()
event handler to ensure search engines can read it.
You cannot add a stylesheet link using the setLinks
function.
function setLinks(links: Array<Link>): Promise<void>;
The links to set.
import { seo } from "@wix/site-seo";
import { createClient } from "@wix/sdk";
import { site } from "@wix/site";
const wixClient = createClient({ host: site.host(), modules: { seo } });
document.addEventListener("DOMContentLoaded", async () => {
try {
await wixClient.seo.setLinks([
{
rel: "canonical",
href: "http://mysite.com/cononical_version",
},
{
rel: "author",
href: "http://mysite.com/janedoe",
},
]);
console.log("links set");
} catch {
console.log("failed setting links");
}
});
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.