- This topic has 5 replies, 2 voices, and was last updated 7 years, 11 months ago by
David.
-
AuthorPosts
-
July 3, 2018 at 12:32 am #614032
Ignacio
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 thanksJuly 3, 2018 at 5:19 am #614231David
StaffCustomer SupportHi 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-Fieldto 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
July 3, 2018 at 10:04 am #614541Ignacio
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
July 3, 2018 at 2:11 pm #614684David
StaffCustomer Supportwp_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.July 4, 2018 at 4:35 am #615057Ignacio
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.July 4, 2018 at 4:38 am #615061David
StaffCustomer SupportYes GP does make it super easy. And its going to get even easier very soon 😉
-
AuthorPosts
- You must be logged in to reply to this topic.