Skip to main content
8 events
when toggle format what by license comment
Oct 29, 2019 at 16:44 vote accept sound wave
Oct 29, 2019 at 16:18 comment added birgire i.e. add_shortcode( $name, function ( $atts, $content, $name ) {
Oct 29, 2019 at 16:10 comment added birgire Note also that the shortcode tag is available as the third input argument of the callback.
Oct 29, 2019 at 16:06 history edited butlerblog CC BY-SA 4.0
added 14 characters in body
Oct 29, 2019 at 16:04 comment added butlerblog ahhh... good point. Or alternatively, you could make it global. I edited to apply use()
Oct 29, 2019 at 15:06 comment added Sally CJ You need to use the use keyword so that the $name is available inside the closure (anonymous function): add_shortcode( $name, function ( $atts ) use ( $name ) {
Oct 29, 2019 at 8:19 comment added sound wave Thank you very much! This works in the sense that the shortcodes are generated, but it seems like that the only problem is the variable name in line 5. I tried by substituting '<div class=con>[block slug=' . $name . ']</div>' with '[slug=' . $name . ']' and the output is [slug=]. Moreover the plugin Query Monitor says there is a PHP error Undefined variable: name for each auto generated shortcode. Is there a way to solve?
Oct 29, 2019 at 2:04 history answered butlerblog CC BY-SA 4.0