1

I'm refering to the question JSON-LD: Using data:post.body in Blogger template.

Surprisingly, <data:post.body> can be used in the meantime. But now I have a new problem: How to eliminate tags, linefeeds and special characters and replace characters like ' and "?

I found something in the kind of the following instead of directly write JSON-LD code, but it does not work:

<script type='text/javascript'>
  var thisDdoesNotWork = removeHtmlTags_And_ChangeSomeCharacters("<data:post.body/>");
  var el = document.createElement('script');
  el.type = 'application/ld+json';
  el.text = JSON.stringify({
    "v1":"thisWorks",
    "v2":"<data:post.thisWorksToo/>",
    "v3":thisDdoesNotWork});
  document.querySelector('head').appendChild(el);

Someone an idea?

Community
  • 1
  • 1
Pmel
  • 83
  • 8

1 Answers1

0

Firstly render the content somewhere in the HTML via

<div class='post-body'>
    <data:post.body/>
</div>

Then, change your code as follows -

el.text = JSON.stringify({
"v1":"thisWorks",
"v2":"<data:post.thisWorksToo/>",
"v3":document.querySelector('.post-body').textContent});

You can also use innerText property (Refer to this question to know the difference between innerText and textContent)

Community
  • 1
  • 1
Prayag Verma
  • 5,581
  • 3
  • 30
  • 56