There are two solutions:
- Use the third argument for the shortcode.
- Use the
use
keyword.
Examples
- The third parameter for each shortcode callback is the name of the shortcode:
foreach ($files1 as $value) {
$new_value = substr($value, 0, -4);
add_shortcode($new_value, function( $attributes, $content, $shortcode ) {
return '<img src="' . PATH . L_ITEMS . $shortcode . '.gif">';
});
}
- Pass the variable you need to the
use
part of the lambda function:
foreach ($files1 as $value) {
$new_value = substr($value, 0, -4);
add_shortcode($new_value, function() use ( $new_value ) {
return '<img src="' . PATH . L_ITEMS . $new_value . '.gif">';
});
}
I think you should register just one shortcode and pass the file as attribute value. That would be faster and easier to debug.