[Support request] Hook to post content anywhere inside a post

Home Forums Support [Support request] Hook to post content anywhere inside a post

Home Forums Support Hook to post content anywhere inside a post

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1640756
    Alejandro

    Hi,

    I used the code below to create a shortcode that insert content within a post.
    If I declare the same function again (to create a different shortcode) the code does not work (obviously).

    Could you help me on this?

    Cheers

    Alex

    php:

    function db_hook_inside_shortcode($atts, $content = null) {
          ob_start();
          do_action('custom_shortcode_hook');
          return ob_get_clean();
    }
    add_shortcode('recursos_shortcode', 'db_hook_inside_shortcode');
    #1640787
    Leo
    Staff
    Customer Support

    Hi there,

    I’m not sure if I understand.

    What are you trying to do here?

    #1640877
    Alejandro

    Hi,
    I’ve just created a shortcode out of a hook to be able to insert it wherever I want.
    The question is: how can I make a second one?
    If I replicate this snippet, the function does not work as the function has been already declared.

    Thank you.

    #1640954
    Leo
    Staff
    Customer Support

    You will need to change the name of recursos_shortcode

    #1642686
    Alejandro

    This is what I was telling earlier… It does not work.
    See the image: https://ibb.co/XWfxCtV

    #1643042
    David
    Staff
    Customer Support

    Hi there,

    there are three parts to that shortcode that need to be unique – that is the shortcode_name, the the_callback_function_name of which you will see it twice in the code, and the custom_shortcode_hook label.

    function the_callback_function_name($atts, $content = null) {
          ob_start();
          do_action('custom_shortcode_hook');
          return ob_get_clean();
    }
    
    add_shortcode('shortcode_name', 'the_callback_function_name');

    As a note: that function is a bit of a hack, and i would only recommend using it in extreme circumstances. Not advisable to have lots of different ones as the extra db queries it will generate can soon mount up.

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