I was create a shortcode which automatically generate shortcodes with given array key and value. Function names does not generate dynamically.
Note: Array KEY = ShortcodeName and Value = WordPress Option field.
add_shortcode("auto_gen", "auto_gen");
function auto_gen() {
$a = array(
"get_address" => "mg_admin_address",
"get_phone" => "mg_admin_phone",
"get_fax" => "mg_admin_fax",
"get_email" => "mg_admin_email",
"get_hrs_mon" => "mg_work_hrs_mon_frd",
"get_hrs_sat" => "mg_work_hrs_sat"
);
foreach ($a as $k => $v) {
if(has_shortcode($k)) {
echo "<br>Found: ". $k;
} else {
add_shortcode($k, $k. "_init");
function $k. "_init"() {
return get_option[$v, ''];
}
}
add_shortcode();
echo $k ." -> ". $v. "<br />";
}
}
There is any possible way to do this.
NOTE:
Here, get_address array key is a shortcode. And it is dynamically generate when It pass though loop. get_address is changable. If I change get_address with get_user_address then get_user_address generate generated. “get_address”, “get_phone” are CHANGABLE at END LEVEL.
Developer also generate shortcodes to access created wp_options useing get_options, simply pushing elements in array. e.g. “shortcode_name” => “option_name”
The function
add_shortcode
has a third parameter that contains the current shortcode, so the same callback can be used multiple times:Another possibility:
Try following code: