I have a foreach loop that creates a function for each array item. I need a unique name for each function created and would like to include the current array item in the function name but don't know how to do this.
At the moment I have the function named as "function ttm_global__shortcode()" however I would like it to be "function ttm_global_$acf_field_shortcode()"
$acf_fields = array("telephone_number", "fax_number", "email_address", "skype");
foreach($acf_fields as $acf_field) {
function ttm_global__shortcode() {
ob_start();
echo get_field($acf_field, 'options');
$output = ob_get_contents();
ob_end_clean();
return $output;
}
add_shortcode($acf_field, 'ttm_global_'.$acf_field.'_shortcode');
}
Thanks
add_shortcode
a callback?? – shiplu.mokadd.im Feb 20 '12 at 17:06