- This topic has 10 replies, 2 voices, and was last updated 5 years, 3 months ago by
Elvin.
-
AuthorPosts
-
October 16, 2019 at 3:16 pm #1036698
Gustav
How do I add a hook in the middle of a blog post?
October 16, 2019 at 4:13 pm #1036730David
StaffCustomer SupportHi there,
can i ask what you want the hook for?
October 16, 2019 at 4:16 pm #1036733Gustav
For Adsense ad codes
October 16, 2019 at 4:29 pm #1036742David
StaffCustomer SupportWould be better to use a plugin like this:
October 16, 2019 at 4:38 pm #1036747Gustav
Yeah. But the hook is far easier to customize when you want your ads to appear on a specific post,category or page. That’s why I prefer the hook to the plugin
October 16, 2019 at 5:16 pm #1036765David
StaffCustomer SupportHooks don’t exist within the content.
There is one method, that feels completely wrong, and that is to register a hook inside a shortcode – heres the PHP snippet to do that:function your_shortcode($atts, $content = null) { ob_start(); do_action('your_hook_name'); return ob_get_clean(); } add_shortcode('shortcode_name', 'your_shortcode');Completely untested for what you require but in theory it should work.
Note: you will want to rename the shortcode function / name and hook.
October 18, 2019 at 8:09 am #1038236Eric
Hey David, thanks for the reply again…
Sorry, I’m not too familiar with shortcodes, registering them in WordPress in particular… I placed the code into the Functions.php right? I tried replacing the name but I think I messed it up somehow?
https://pasteboard.co/ICyz6zZ.png
Could you give me a few steps as to how to complete this solution? So, I’m assuming I need to place this code into functions.php, then create another hook? How do I connect the two of them exactly?
Thanks for the help and sorry about the inexperience.
October 18, 2019 at 8:27 am #1038253David
StaffCustomer SupportE.g
function db_hook_inside_shortcode($atts, $content = null) { ob_start(); do_action('custom_shortcode_hook'); return ob_get_clean(); } add_shortcode('hooky_shortcode', 'db_hook_inside_shortcode');Then in your post you add the shortcode:
[hooky_shortcode]And in Elements you would choose custom hook and add
custom_shortcode_hookOctober 18, 2019 at 8:37 am #1038263Eric
It worked! Thank you David! Generatepress RULES… 🙂
October 13, 2020 at 8:19 pm #1487770Ravi Dixit
Hey David, I also want to add a hook inside the content. I check the codes you gave but I didn’t understand it.
can you please help me understand this?October 13, 2020 at 8:37 pm #1487787Elvin
StaffCustomer SupportHi Ravi,
Can you open up a new topic for your concern?
We’ll make sure to address your concern there. Thank you. 🙂
-
AuthorPosts
- The topic ‘Hook’ is closed to new replies.