Archived topic
Is it possible to add to header script from content-single.php?
1 reply · Started by Matthew on November 21, 2019
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.
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.