WordPress.org

Support

Support » Requests and Feedback » [shortcode] Parameterized shortcode callback via new add_shortcode() arg

[shortcode] Parameterized shortcode callback via new add_shortcode() arg

  • A new third argument to add_shortcode() would allow parameterized shortcodes via callback overloading:

    function add_shortcode($tag, $func, $merge_atts)

    Example:

    add_shortcode('foo1', 'mycallback', array('arg1' => '1'))
    add_shortcode('foo2', 'mycallback', array('arg1' => '2'))

    I do lots of text replacements via shortcodes, and currently have to finagle this through content ([foo]arg1[/foo][foo]arg2[/foo] versus [foo1/][foo2/]).

    I can’t think of any downside to parameterized callbacks.

Viewing 1 replies (of 1 total)
  • Sorry to reply to my own post, but I now realize that the shortcode callback can determine which code matched the shortcode regex (via the hitherto undocumented third argument to the callback). This makes it possible to implement the above behavior by testing for shortcode name, rather than through default parameters on the add_shortcode() call. This could still be a useful feature but there is a good alternative already in place.

Viewing 1 replies (of 1 total)
  • The topic ‘[shortcode] Parameterized shortcode callback via new add_shortcode() arg’ is closed to new replies.
Skip to toolbar