How can I add a custom JSON script to ONLY the homepage header?

How can I add a custom JSON script to ONLY the homepage header? (I prefer to use one of my custom, magic SEO JSON LD scripts than use the Snippets plugin)

I am using Stack = Renew, already have child theme installed.

Anyone know how to do this?

Thnx!

Hello @giveitlegs,

Thanks for writing in!

How can I add a custom JSON script to ONLY the homepage header?
Since the child theme is set up, please add the following code in your child theme’s functions.php file

function add_json_script(){
  if ( is_home() ) : ?>

    // Add your JSON script here

  <?php endif;
}
add_action('wp_head', 'add_json_script'); 

We would loved to know if this has work for you. Thank you.

Hmm. It did add it, but it adds onpage below the tags when I go to inspect it in the console. Google Structured Data Validator didn’t pick it up there… which is also odd, because usually it does (even if it’s in the body)…

website is https://travelcrush.org
(just FYI)

Hello @giveitlegs,

We can make it as a priority. Have the code updated and use this:

function add_json_script(){
  if ( is_home() ) : ?>

    // Add your JSON script here

  <?php endif;
}
add_action('wp_head', 'add_json_script', 5);

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.