I need help printing javascript variable into a JSON object with its value which it has fetched. Please check my code:
<script type="text/javascript" data-ampdevmode="">
var postid = document.querySelector('.status-publish').getAttribute('id').replace("post-", "");
</script>
<script type="text/javascript" data-ampdevmode="">
console.log(postid);
</script>
<amp-state id="wpp-json-amp">
<script type="application/json" id="wpp-json">
{
"ID": postid
}
</script>
</amp-state>
Here "postid" will get the id of WordPress post.
Also its not printing the inside content of <script type="application/json" id="wpp-json"> on amp page.. can anyone help me with this?
asked Feb 13, 2024 at 21:23
GoSSDHosting
1421 silver badge12 bronze badges
lang-js
status-publish? Please provide some more code in case that element does exist in the DOM somewhere (if not, that's certainly at least a part of your problem). Please also be more precise what exactly it is you're trying to do? Currently this looks very unusal with a lot of<script/>tags but practically almost no code in them, so it's very hard to tell what you're trying to do.