Archived topic
Hook to post content anywhere inside a post
5 replies · Started by Alejandro on January 31, 2021
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');
Hi there,
I'm not sure if I understand.
What are you trying to do here?
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.
You will need to change the name of recursos_shortcode
This is what I was telling earlier... It does not work.
See the image: https://ibb.co/XWfxCtV
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.