Archived topic
Post Script Area
7 replies · Started by Anne on March 7, 2021
I've looked through the documentation and don't see the answer. Basically, I want something like SIMPLE CSS except I want to use it for scripts and provide a location. Typically, JSON+LD for schema markup which is unique to the post/page, not something global. This mostly "about" schema.
I made the mistake of thinking the previous scripts section I had on my previous theme was native to WordPress. I now believe it was part of Genesis.
I saw some docs about creating a hook, which I did. However, I don't see any way in which it can appear in the editor so I can add the schema.
In the meantime, I'll look for a plugin.
Thanks in advance
Hi there,
I'm not sure I fully understand what you mean but it seems like you want something like a conditional hook to hook your scripts into the <head>.
If that's actually the case, then you can definitely do that with the Hook Element.
You can also set the display rule location as well if you require separate scripts for posts and pages.
Hi Elvin,
no, I do not want this in the <head>.
After I write an article, I'd like to see a box where I can write my JSON code. While I need the box on every post, the content will differ.
I've attached a link from a Genesis support page that has a picture.

Hi there,
thats either a Genesis or Plugin function. If you want to embed scripts into the site then you would need to use a combination of hooks and custom fields ( which an be displayed in the Post Editor ). Let us know if you want a hand setting that up.
Hi,
Thanks, Dave. Using the docs, I built an element.
Type: Hook - generate_before_main_content
Location: Entire Site
Exclusions: none
Users: none
I thought I could add that element underneath the Gutenberg editor where I have content boxes for other plugins like Yoast, Table of Contents, etc.
That's where I need help.
Elements only work on the front end - they don't add anything to the Editor itself.
Without plugins you can use WP Custom Fields to set the Key ( name of the CF ) and value ( eg. the Script ):
https://wordpress.org/support/article/custom-fields/
Note the Value must include any <script></script> tags.
Then using a Hook Element you can return the value by adding this PHP Snippet:
<?php echo get_post_meta(get_the_ID(), 'key', true); ?>
The key will match the name of your custom field.
For example with a new custom field i could add:
Name: header_script
Value: my custom script
Then the above code would look like this:
<?php echo get_post_meta(get_the_ID(), 'header_script', true); ?>
If you want a more friendly UI in the WP editor you can use the Meta Box plugin or ACF to create those field inputs.
Thanks. I'll may give ACF a try. Still looking at schema plugins. I also need to see if there is any way to retrieve all the previous JSON.
You're welcome