question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Structured Data is not displaying

See original GitHub issue

Hi i have tried the following code. But its not working

import React, { PropTypes } from 'react';
import Helmet from 'react-helmet';
const StructuredDataComponent = (props) => {
  console.log(props.type);
  console.log('StructuredDataComponentLog');
  return (
  <div>
    <Helmet
    script={[{
      'type': 'application/ld+json',
      'innerHTML': `{
        '@context': 'http://schema.org',
        '@type': 'NewsArticle'
      }`
    }]}
    />
 </div>
  );
};
StructuredDataComponent.propTypes = {
  type: PropTypes.string.isRequired,
};
export default StructuredDataComponent;

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
lolobossecommented, Jul 6, 2017

Hello there, I’m running in the same issue with server side rendering but the case is slightly more complex for me:

<Helmet
        title={title}
        meta={[
          { name: 'keywords', content: genKeywords(title, description, company) },
          { property: 'og:title', content: title },
          { property: 'og:type', content: 'website' },
          { property: 'og:image', content: picture_url || categoryImage || 'http://jobninja.eu/assets/img/freeze/banner.jpg' },
          { property: 'og:description', content: description },
          { property: 'og:url', content: `${SITE_URL}/jobs/${id}` },
          { name: 'description', content: description },
          { name: 'bullshit', content: JSON.stringify({
            '@context': 'http://schema.org',
            '@type': 'JobPosting',
            datePosted: created_at,
            employmentType: 'Vollzeit',
            jobLocation: {
              '@type': 'Place',
              address: {
                '@type': 'PostalAddress',
                addressLocality: location ? location.city : location,
                addressRegion: 'DE'
              }
            },
            occupationalCategory: category,
            description: description,
            title: title,
            url: `${SITE_URL}/jobs/${id}`
          })}
        ]}
        link={[
          { rel: 'canonical', href: `${SITE_URL}/jobs/${id}` }
        ]}
        script={[{
          type: 'application/ld+json',
          innerHTML: JSON.stringify({
            '@context': 'http://schema.org',
            '@type': 'JobPosting',
            datePosted: created_at,
            employmentType: 'Vollzeit',
            jobLocation: {
              '@type': 'Place',
              address: {
                '@type': 'PostalAddress',
                addressLocality: location ? location.city : location,
                addressRegion: 'DE'
              }
            },
            occupationalCategory: category,
            description: description,
            title: title,
            url: `${SITE_URL}/jobs/${id}`
          })
        }]}
      />

And the issue is the following:

  • I see every item when I render this helmet to a browser (meaning that the code works)
  • When I call the source page, I get:
<meta data-react-helmet="true" name="keywords" content="My Super keywords"/>
<meta data-react-helmet="true" property="og:title" content="My Super title"/>
<meta data-react-helmet="true" property="og:type" content="website"/>
<meta data-react-helmet="true" property="og:image" content="http://3w6kx9401skz1bup4i1gs9ne.wpengine.netdna-cdn.com/wp-content/uploads/2016/09/telegraph-1.jpg"/>
<meta data-react-helmet="true" property="og:description" content="My super description"/>
<meta data-react-helmet="true" property="og:url" content="https://dev.jobninja.com/jobs/416"/>
<meta data-react-helmet="true" name="description" content="My super description"/>
<meta data-react-helmet="true" name="bullshit" content="The json+ld that expect is ok and rendered but only in meta"/>
<title data-react-helmet="true">My title</title>
<link data-react-helmet="true" rel="canonical" href="https://dev.jobninja.com/jobs/416"/>
<!-- BUT NO SCRIPT!! -->

However, in a normal browser, after I loaded the page I get this script element.

Therefore, I think that I’m missing something but cannot figure out what.

Btw my server side code looks like this:

const renderHTML = (markup, store) => {
  const head = Helmet.rewind();
  const html = ReactDOM.renderToStaticMarkup(
    <Html
      head={head}
      markup={markup}
      store={store}
    />
  );
  return `<!doctype html>\n${html}`;
};
3reactions
enapupecommented, Dec 6, 2018

Nevermind, I forgot to call head.script.toString() on my base template.

Read more comments on GitHub >

github_iconTop Results From Across the Web

8 reasons why your structured data is not showing in search
Summary of why your structured data isn't showing up in search · Google is not aware that your site has schema markup because...
Read more >
Troubleshoot Structured Data not Showing in Search
Reasons Why Rich Results Not Showing in SERP · 1. Google hasn't crawled your site since the change was made · 2. Not...
Read more >
12 Reasons Why Your Rich Snippets Aren't Showing
5. Your Structured Data Mark Up Is Done Incorrectly ... This is the most common reason why rich snippets aren't showing for pages...
Read more >
Structured data not working - WordPress.org
Then I found out that the structured data is not working on the product pages. Information is missing such as: Price, sku and...
Read more >
Google Structured Data Helper not displaying website
After it is done loading on the 'Tag Page', the webpage I am trying to tag does not display on the left side...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found