[Resolved] hooks in posts

Home Forums Support [Resolved] hooks in posts

Home Forums Support hooks in posts

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #614032
    chete

    Hi.
    The hooks zone is perfect for adding code in certain zones. But I’m looking for a way to add that code individually in the posts. That is, in the post edition I can add code to the header hook. So each post will have a different thing added.
    Any recommendations?
    REgards and thanks

    GeneratePress 2.1.2
    GP Premium 1.6.2
    #614231
    David
    Staff
    Customer Support

    Hi there,

    simplest method is to use the WordPress Custom Fields, create your field and add the data you want to display and then add this to the hook changing Your-Custom-Field to your field name.

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    echo get_post_meta($postid, 'Your-Custom-Field', true);
    wp_reset_query();
    ?>

    You can also do this in Page Headers, same process of creating the custom field but then simply add this template tag:

    {{custom_field.name}}

    The name being the name of the field

    #614541
    chete

    Hi David

    Yes, I had thought that one option could be a custom field text, and then make the header display that field if it contains something. Just what you proposed. But I that code would not have known how to do it hehe. Thank you so much for the code. Works perfectly

    One last question. In case I don’t have the option to generatepress and the hooks, I can’t find a plugin that allows me to manage the hooks in an easy way.
    What I’ve done is add your code in:

    function custom_hook() {
    	.........
    }
    add_action( 'wp_head', 'custom_hook' );

    and it also works.

    Regards

    #614684
    David
    Staff
    Customer Support

    wp_head and wp_footer hooks are part of WordPress core so should be in all themes. They however should be used for adding scripts / meta data etc. not really for outputting content. There are other WP ones you can output to such as those in the comments box.
    The rest will be theme or plugin dependent. So will vary from one to another. I think GP set the standard for introducing such an array of hooks that are accessible.

    #615057
    chete

    yes, yes, the hooks should be, but usually the themes don’t give the ease of management as GP does.
    And correct, they’re for adding scripts. I’ll add json, for the schema.
    Thank you so much for your help, David.

    #615061
    David
    Staff
    Customer Support

    Yes GP does make it super easy. And its going to get even easier very soon 😉

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