Title: [shortcode] Parameterized shortcode callback via new add_shortcode() arg
Last modified: August 19, 2016

---

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

 *  [spinality](https://wordpress.org/support/users/spinality/)
 * (@spinality)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/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)

 *  Thread Starter [spinality](https://wordpress.org/support/users/spinality/)
 * (@spinality)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/shortcode-parameterized-shortcode-callback-via-new-add_shortcode-arg/#post-1194798)
 * 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.

## Tags

 * [callback](https://wordpress.org/support/topic-tag/callback/)
 * [parameter](https://wordpress.org/support/topic-tag/parameter/)
 * [request](https://wordpress.org/support/topic-tag/request/)
 * [shortcode](https://wordpress.org/support/topic-tag/shortcode/)

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 1 reply
 * 1 participant
 * Last reply from: [spinality](https://wordpress.org/support/users/spinality/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/shortcode-parameterized-shortcode-callback-via-new-add_shortcode-arg/#post-1194798)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
