[Support request] Hook

Home Forums Support [Support request] Hook

Home Forums Support Hook

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1036698
    Gustav

    How do I add a hook in the middle of a blog post?

    #1036730
    David
    Staff
    Customer Support

    Hi there,

    can i ask what you want the hook for?

    #1036733
    Gustav

    For Adsense ad codes

    #1036742
    David
    Staff
    Customer Support

    Would be better to use a plugin like this:

    https://en-gb.wordpress.org/plugins/ad-inserter/

    #1036747
    Gustav

    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

    #1036765
    David
    Staff
    Customer Support

    Hooks 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.

    #1038236
    Eric

    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.

    #1038253
    David
    Staff
    Customer Support

    E.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_hook

    #1038263
    Eric

    It worked! Thank you David! Generatepress RULES… ๐Ÿ™‚

    #1487770
    Ravi 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?

    #1487787
    Elvin
    Staff
    Customer Support

    Hi Ravi,

    Can you open up a new topic for your concern?

    We’ll make sure to address your concern there. Thank you. ๐Ÿ™‚

Viewing 11 posts - 1 through 11 (of 11 total)
  • The topic ‘Hook’ is closed to new replies.