CorvidReference

wix-seo

The wix-seo module contains functionality for working with your site's SEO from client-side code.

Because you want the SEO data you set to be read by search engines, you should always set such data in the onReady() event handler.

To use the SEO API, import wixSeo from the wix-seo module:

   import wixSeo from 'wix-seo';

Table of Contents

PROPERTIES

?
Store values associated with an object.
linksGets the page's SEO-related link tags.
metaTagsGets the page's SEO-related meta tags.
structuredDataGets the page's structured data.
titleGets the page's title.

OBJECTS

?
Objects used when setting, getting, or calling the properties and methods listed above.
LinkAn object representing a link tag.
MetaTagAn object representing a meta tag.

links

Gets the page's SEO-related link tags.

Description

Use the links property to get a page's SEO-related link tags which provide additional SEO information about your page. For example, the tags may contain a link to a canonical or alternate version of the current page.

Syntax

get links(): Array<Link>
TYPE
?
Array<Link>

Examples

Get a page's link tags

import wixSeo from 'wix-seo';

// ...

let links = wixSeo.links;

/* links:
 *
 * [
 *   {
 *     "rel": "canonical", 
 *     "href": "http://mysite.com/canonical_version"
 *   }, {
 *     "rel": "author",  
 *     "href": "http://mysite.com/janedoe"
 *   }
 * ]
 */

metaTags

Gets the page's SEO-related meta tags.

Description

The metaTags property retrieves the SEO-related meta tags from the head of the page.

Syntax

get metaTags(): Array<MetaTag>
TYPE
?
The kind of data the property stores.
Array<MetaTag>

Examples

Get a page's meta tags

import wixSeo from 'wix-seo';

// ...

let metaTags = wixSeo.metaTags;

/* metaTags:
 *
 * [
 *   {
 *     "name": "robots",
 *     "content": "noindex"
 *   }, {
 *     "property": "og:image",
 *     "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
 *   }
 * ]
 */

structuredData

Gets the page's structured data.

Description

The structured data on your page helps search engines understand more about your page and your business so they can display a richer snippet of your pages in search results.

Set the structured data with a list of structured data objects in the JSON-LD format as defined by schema.org.

Syntax

get structuredData(): Array<Object>
TYPE
?
The kind of data the property stores.
Array<Object>

Examples

Get a page's structured data

import wixSeo from 'wix-seo';

// ...

let structuredData = wixSeo.structuredData;

/* structuredData:
 *
 * [ 
 *   {
 *     "@context": "http://schema.org",
 *     "@type": "Organization",
 *     "name": "My Organization Name",
 *     "url": "https://www.myorgdomain.com"
 *   },
 *   {
 *     "@context": "http://schema.org",
 *     "@type": "Person",
 *     "email": "mailto:john.doe@somedomain.com",
 *     "jobTitle": "Professor",
 *     "name": "John Doe",
 *     "telephone": "(555) 555-555"
 *   }
 * ]
 */

title

Gets the page's title.

Syntax

get title(): string
TYPE
?
The kind of data the property stores.
string

Examples

Get the SEO title

import wixSeo from 'wix-seo';

// ...

let title = wixSeo.title; // "Page Title"

setLinks( )

Sets the page's SEO-related link tags.

Description

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.

Because you want the links you set to be read by search engines, you should always set them in the onReady() event handler.

Note

You cannot add a stylesheet link using the setLinks function.

Syntax

function setLinks(links: Array<Link>): Promise<void>
PARAMETERS
?
links
Array<Link>
The links to set.
RETURN VALUE
?
Promise<void>
Fulfilled - When the link tags are set.

Examples

Get a page's link tags

import wixSeo from 'wix-seo';

// ...

$w.onReady( () => {
  wixSeo.setLinks(
    [
      {
        "rel": "canonical", 
        "href": "http://mysite.com/cononical_version"
      }, {
        "rel": "author", 
        "href": "http://mysite.com/janedoe"
      }
    ]
  )
  .then( () => {
    console.log("links set");
  } )
  .catch( () => {
    console.log("failed setting links");
  } );
} );

setMetaTags( )

Sets the page's SEO-related meta tags.

Description

The setMetaTags() function creates SEO-related meta tags in the head of the page.

When setting og:image meta tags, the content can be and external image URL or a Media Manager image URL as described here.

Because you want the meta tags you set to be read by search engines, you should always set them in the onReady() event handler.

Note

Do not use setMetaTags() to create tags for title. Use the setTitle() function instead.

Syntax

function setMetaTags(The: Array<MetaTag>): Promise<void>
PARAMETERS
?
Values that you pass to a function.
The
Array<MetaTag>
meta tags to set.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the meta tags are set.

Examples

Set a page's meta tags

import wixSeo from 'wix-seo';

// ...

$w.onReady( () => {
  wixSeo.setMetaTags(
    [
      {
        "name": "robots",
        "content": "noindex"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ]
  )
  .then( () => {
    console.log("meta tags set");
  } )
  .catch( () => {
    console.log("failed setting meta tags");
  } );
} );

setStructuredData( )

Sets the page's structured data.

Description

The structured data on your page helps search engines understand more about your page and your business so they can display a richer snippet of your pages in search results.

Because you want the structured data you set to be read by search engines, you should always set it in the onReady() event handler.

Syntax

function setStructuredData(structuredData: Array<Object>): Promise<void>
PARAMETERS
?
Values that you pass to a function.
structuredData
Array<Object>
List of structured data objects in the JSON-LD format as defined by schema.org.
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the structured data is set.

Examples

Set a page's structured data

import wixSeo from 'wix-seo';

// ...

$w.onReady( () => {
  wixSeo.setStructuredData(
    [ 
      {
        "@context": "http://schema.org",
        "@type": "Organization",
        "name": "My Organization Name",
        "url": "https://www.myorgdomain.com"
      },
      {
        "@context": "http://schema.org",
        "@type": "Person",
        "email": "mailto:john.doe@somedomain.com",
        "jobTitle": "Professor",
        "name": "John Doe",
        "telephone": "(555) 555-555"
      }
    ]
  )
  .then( () => {
    console.log("structured data set");
  } )
  .catch( () => {
    console.log("failed setting structured data");
  } );
} );

setTitle( )

Sets the page's title.

Description

Because you want the title you set to be read by search engines, you should always set it in the onReady() event handler.

Syntax

function setTitle(): Promise<void>
RETURN VALUE
?
Value that a function evaluates to when it is finished running.
Promise<void>
Fulfilled - When the title is set.

Examples

Set a page's SEO title

import wixSeo from 'wix-seo';

// ...

$w.onReady( () => {
  wixSeo.setTitle("New Title")
    .then( () => {
      console.log("title set");
    } )
    .catch( () => {
      console.log("failed setting title");
    } );

} );

Link

An object representing a link tag.

See Also

links, setLinks( )

Syntax

type Link = {
  rel: string
  href: string
}
MEMBERS
?
rel(Optional)
string
The relationship of the linked resource to the current page.
href(Optional)
string
The URL of the linked resource.

Examples

Get a page's link tags

import wixSeo from 'wix-seo';

// ...

let links = wixSeo.links;

/* links:
 *
 * [
 *   {
 *     "rel": "canonical", 
 *     "href": "http://mysite.com/canonical_version"
 *   }, {
 *     "rel": "author",  
 *     "href": "http://mysite.com/janedoe"
 *   }
 * ]
 */

Get a page's link tags

import wixSeo from 'wix-seo';

// ...

$w.onReady( () => {
  wixSeo.setLinks(
    [
      {
        "rel": "canonical", 
        "href": "http://mysite.com/cononical_version"
      }, {
        "rel": "author", 
        "href": "http://mysite.com/janedoe"
      }
    ]
  )
  .then( () => {
    console.log("links set");
  } )
  .catch( () => {
    console.log("failed setting links");
  } );
} );

MetaTag

An object representing a meta tag.

Description

The keys in the object represent the keys in the tag and the values in the object represent the values in the tag.

For example:

 {
   "property": "og:image",
   "content": "https://.../Wix+logo.jpg"
 }

Produces:

 <meta property="og:image" content="https://.../Wix+logo.jpg"/>

See Also

metaTags, setMetaTags( )

Syntax

type MetaTag = {
  name: string
  property: string
  http-equiv: string
  content: string
}
MEMBERS
?
The properties of an object.
name(Optional)
string
Name of the meta tag. Either name or property are required.
property(Optional)
string
Name of the meta tag property. Either property or name are required.
http-equiv(Optional)
string
HTTP header that corresponds to the content.
content
string

Meta tag value. For og:image meta tags, the content can be an external image URL or a Media Manager image URL as described here.

Examples

Get a page's meta tags

import wixSeo from 'wix-seo';

// ...

let metaTags = wixSeo.metaTags;

/* metaTags:
 *
 * [
 *   {
 *     "name": "robots",
 *     "content": "noindex"
 *   }, {
 *     "property": "og:image",
 *     "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
 *   }
 * ]
 */

Set a page's meta tags

import wixSeo from 'wix-seo';

// ...

$w.onReady( () => {
  wixSeo.setMetaTags(
    [
      {
        "name": "robots",
        "content": "noindex"
      }, {
        "property": "og:image",
        "content": "wix:image://v1/6...2.jpg/a.jpg#originWidth=970&originHeight=120"
      }
    ]
  )
  .then( () => {
    console.log("meta tags set");
  } )
  .catch( () => {
    console.log("failed setting meta tags");
  } );
} );