I'm trying to pass a variable into the add_shortcode function to be used as the shortcode name but it does not seem to be working. Is there a way that I can pass a variable similar to this?
foreach ($files1 as $value) {
$new_value = substr($value, 0, -4);
add_shortcode($new_value, function() {
return '<img src="' . PATH . L_ITEMS . $new_value . '.gif">';
});
}
$file1
has 100 values, you are going to create 100 shortcodes which you are going to use how?class
anduse
. But I wonder if you really need multiple shortcodes here, why not a single shortcode with an attribute?