Site logo

[Resolved] Display custom fields in page

Home Forums Support [Resolved] Display custom fields in page

Home Forums Support Display custom fields in page

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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&#8221;,”…</script>

    How do I show this specific custom field on every post?

    #2565322
    Fernando
    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.

    #2565348
    Oliver

    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.

    #2565354
    Fernando
    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

    #2565459
    Oliver

    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” );

    #2565474
    Fernando
    Customer Support

    Sorry, where do you want to add this code exactly?

    #2565476
    Oliver

    at the end of a post page, preferably after the site footer?

    Preferably after this class.

    #2565478
    Fernando
    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.

    #2566215
    Oliver

    that works thank you!

    #2566614
    Fernando
    Customer Support

    You’re welcome, Oliver!

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