current_shortcode() – detect currently used shortcode

This is untested, but the callback function is provided with an array of arguments, $args which give (if any) the paramters provided with the shortocode. The zeroth entry sometimes contains the name of the shortcode used (e.g. public_email). By sometimes I mean…

The zeroeth entry of the attributes array ($atts[0]) will contain the string that matched the shortcode regex, but ONLY if that differs from the callback name, which otherwise appears as the third argument to the callback function.

(See the Codex). For your purposes then $atts[0] will contain either public_email, public_phone etc.

function shortcode_handler($atts,$content=NULL){
     if(!isset($atts[0]))
         return; //error?

     switch($atts[0]):
         case 'public_email':
              //deal with this case
              break;
         case 'public_phone':
              //deal with this case
              break;
         case 'public_something':
              //deal with this case
              break;
     endswitch;   
}

Leave a Comment