- This topic has 9 replies, 2 voices, and was last updated 3 years, 3 months ago by
Fernando.
-
AuthorPosts
-
March 12, 2023 at 5:40 pm #2565320
Oliver
I added a custom field in my post which contains custom schema.
e.g. <script type=”application/ld+json”>{“@context”:”http://schema.org”,”…</script>
How do I show this specific custom field on every post?
March 12, 2023 at 5:45 pm #2565322Fernando Customer Support
Hi Oliver,
That would need custom development which would be out of our scope of support. It should be something like this: https://developer.wordpress.org/reference/hooks/wp_head/#:~:text=or%20for%20inline%20scripts%20which%20need%20to%20be%20placed%20in%20the%20head%2C
Just replace the script with a
get_post_meta(YOUR-META-FIELD-NAME);add work your way through.What you can do in GeneratePress is to create a Hook Element for each post and that schema script one by one.
March 12, 2023 at 6:35 pm #2565348Oliver
Hi Fernando,
Thanks! but the issue with adding a hook element for each post is too much maintainability and I want to keep the custom schema on each edit post page.
March 12, 2023 at 6:45 pm #2565354Fernando Customer Support
Yes, you would need a custom code to hook your post meta field manually to the Head or somewhere you prefer.
This would be out of our scope, however. It would be good to ask for recommendations in our Facebook group as well: https://www.facebook.com/groups/1113359788719597
March 12, 2023 at 11:09 pm #2565459Oliver
Here is the code but how do I add it after the
?This seems to add it at the end of
function after_post_content($content){
if ( is_singular( ‘post’) ) {
$cf = get_post_meta( get_the_ID(), ‘custom_schema’, true );
if( ! empty( $cf ) ) {
$content .= $cf;
}
}
return $content;
}
add_filter( “the_content”, “after_post_content” );March 12, 2023 at 11:30 pm #2565474Fernando Customer Support
Sorry, where do you want to add this code exactly?
March 12, 2023 at 11:33 pm #2565476Oliver
at the end of a post page, preferably after the site footer?
Preferably after this class.
…March 12, 2023 at 11:35 pm #2565478Fernando Customer Support
Try using the wp_footer hook instead.
Reference: https://developer.wordpress.org/reference/hooks/wp_footer/
That’s where scripts are usually placed.
March 13, 2023 at 8:56 am #2566215Oliver
that works thank you!
March 13, 2023 at 5:01 pm #2566614Fernando Customer Support
You’re welcome, Oliver!
-
AuthorPosts
- You must be logged in to reply to this topic.