[Support request] Is it possible to add to header script from content-single.php?

Home Forums Support Is it possible to add to header script from content-single.php?

  • This topic has 1 reply, 2 voices, and was last updated 10 months ago by Tom.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1071679
    Matthew

    I want to custom code my jsdon-ld on the fly inside of my content-single.php file. Is this possible or is the header already generated?

    See, in my content-single.php page, I do a TON of heavy lifting with PHP on some ACF data fields in my posts-meta table. So I don’t have the data I need for the jsdon-ld until I run the code inside my content-single.php.

    Is there a simple way to do make this work?

    Also, I might add that Google doesn’t require schema in a <script> tag to appear in the header, it can appear in the body. But I was just curious if there is a way to get it in the header at the point in time that content-single.php is executing.

    #1072798
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    If you’re adding the code into content-single.php, I don’t think it’s possible to have it placed in the header – it would show up with all of the other HTML in that file.

    However, you should be able to access all of the same data you’re accessing in that template file inside a hook like `wp_head.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.