I think the most straight forward is querying the database directly, looking for the attachment hello-5.jpg
inside wp_postmeta
table to get its ID. And from there, use a regular WP function to pull the URL:
function head($atts, $content = null) {
extract( shortcode_atts( array(
'color' => '#333',
'banner' => 'visible',
'subject' => 'Subject',
'image' => 'http://example.com/default_image.jpg',
), $atts ) );
// The attribute image was passed in the shortcode [head image="hello-5.jpg"]
if( $image != 'http://example.com/default_image.jpg' ) {
global $wpdb;
$attachment_id = $wpdb->get_var(
$wpdb->prepare( "
SELECT post_id
FROM $wpdb->postmeta
WHERE meta_value LIKE %s
AND meta_key = '_wp_attached_file'
", "%{$image}%"
)
);
// Found it, change the $image URL
if( $attachment_id )
$image = wp_get_attachment_image_src( $attachment_id, 'full' );
}
return "<div class='gridacc'>
<h2 style='background:{$color}'>{$subject}</h2>
<div class='photo' style='display: {$banner}ne'>
<img src='{$image}' alt=''>
</div>
<dl>".do_shortcode($content)."</dl>
</div>";
}
The following Q&A shows how to use Ajax to improve the interface of Shortcode TinyMCE buttons:
Call PHP function inside TinyMCE modal window on the WordPress backend