insert structured data into head section

Posted in: Newspaper
Post count: 28

I need to insert code like this:
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"logo": "http://www.example.com/images/logo.png"
}
</script>
</head>

only in the homepage. If I use the “Google Analytics” section in the theme panel, this code will spread to all pages.
How can I put this only into homepage?

Post count: 35449

Hello,

Please try in this way -> http://prntscr.com/pgambn -> http://prntscr.com/pgamr3
<script>
jQuery(document).ready(function($){
if ( $('body').hasClass('home')) {
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"logo": "http://www.example.com/images/logo.png"
}
}
});
</script>

This should work!
Thank you!

Post count: 28

thanks I will try

Post count: 28

doesnt work, because I need a “particular” script to insert like:
https://jsonld.com/organization/
so I need a script with a type, I tried something like
<script>
jQuery(document).ready(function($){
if ( $('body').hasClass('home')) {

<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://www.notizieoggi24.it",
"logo": "https://www.notizieoggi24.it/wp-content/uploads/2019/09/logo-notizie-oggi-24.png"
}
</script>
}
});
</script>

but didnt work. However I saw the jQuery code into head section from HTML source code

Post count: 35449

Hello,

Your code is not working because you can not have a script tag inside the script type
<script>
<script>
</script>
</script>

it must be like this
<script>
</script>
<script>
</script>

Thank you!

Post count: 28

yes but I need the entire script with “type etc” inside the other script due the jquery function

Post count: 35449

Hi,

Try this :

<script>
jQuery(document).ready(function($){
if ( $('body').hasClass('home')) {
{
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"logo": "http://www.example.com/images/logo.png"
}
</script>
<script>
}
}
});
</script>

or this :

<script type="application/ld+json">
jQuery(document).ready(function($){
if ( $('body').hasClass('home')) {
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "http://www.example.com",
"logo": "http://www.example.com/images/logo.png"
}
}
});
</script>

-> https://stackoverflow.com/questions/38670851/whats-a-script-type-application-ldjsonjsonobj-script-in-a-head-sec

Post count: 28

I will try, thanks

Post count: 28

Seems to work thanks

Post count: 28

works but appears on all pages and not only homepage.
is there some file .php wheither I can put the code?

Post count: 28

maybe something like:
https://wordpress.stackexchange.com/questions/194516/google-analytics-tracking-code-on-just-one-page
is there some file .php to put this? (maybe with the id of page)

Post count: 28
Post count: 35449

Hi,

I’m glad that you find a solution.
If you have more questions regarding our theme, just let us know!

Thank you!

Viewing 13 posts - 1 through 13 (of 13 total)
The forum ‘Newspaper’ is closed to new topics and replies.