Step 3: Adding Schema to Your Page

Schema markup is code added to your webpages to better enable search engines to classify your content and deliver relevant results to consumers. To learn more about schema and the types of data they can be applied to, visit schema.org.

Our recommended approach for adding schema to your webpage is to use Knowledge Tags (for more details see our Working with Knowledge Tags guide . However, you can also leverage the Content Delivery API to generate schema from your information in Knowledge Graph by sending a request to the Entities Schema: Get endpoint.

Here’s an example request in JavaScript to retrieve schema for a specific entity:

$(document).ready(function () {
  entityID = '<ENTITY_ID>',
  entityType = '<ENTITY_TYPE>',
  api_key = '<YOUR_API_KEY>',
  vParam = 'YYYYMMDD',
  language = '2_CHARACTER_LANGUAGE_PROFILE', // Ex: ‘EN’
  $.ajax({
    type: 'GET',
    url : 'https://cdn.yextapis.com/v2/accounts/me/entityschema/' + entityType + '/' + entityID + 
    '/' + language '?api_key=' + api_key + '&v=' + vParam,
    success: function(data, textStatus, xhr){
      renderSchema(JSON.parse(xhr.responseText).response);
    }, error: function(xhr, textStatus, errorThrown) {
      console.log('Unable to load data')
    }
  });
});

To finish, you can create the HTML structure for the schema and add it to your page’s HTML. Here’s an example that you can add to the previous JavaScript code sample:

function renderSchema(answer) {
    var html = '<script type="application/ld+json">'

    html += JSON.stringify(answer);

    html += '</script>'

    // Add it to your HTML
    $("#elementID").after(html)
  return;
 }
Feedback