Thank you for reaching out to us. I have submitted a message to the developers to investigate further your request.
Kind regards.
That code looks wrong to me because you are passing the $download_id in the following line of code when that function takes the “attachment_id”:
$download_thumb_alt = get_post_meta($download_id, '_wp_attachment_image_alt', true);
As far as I know it takes the attachment ID which is different than download ID so that won’t return anything.
@mra13 Thanks for your reply.
Sounds like I may need to use the attachment_url_to_postid() function by converting the $download_thumb_url into its attachment ID. Hence the source codes may look so:
// Simple Download Monitor: Add ALT attribute to download fancy 2 thumbnail
if ( is_plugin_active('simple-download-monitor/main.php') ) {
add_filter('sdm_download_fancy_2_thumbnail', function($thumb_output, $args) {
$download_id = $args['id'];
$download_thumb_url = get_post_meta($download_id, 'sdm_upload_thumbnail', true);
$attachment_id = attachment_url_to_postid($download_thumb_url);
$download_thumb_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
$thumb_output = '<img src="' . $download_thumb_url . '" alt="' . $download_thumb_alt . '" />';
return $thumb_output;
}, 10, 2);
}
Will find out if this works once I hand it over to my web administrator for him to insert this code into functions.php
The thumbnail URL is actually not the attachment URL. Remember, we don’t force users to upload the thumbnail to their server (it’s an option but not mandatory). A lot of users just enter an image URL from their amazon S3 account for example. So the plugin only saves the static image URL value in the “Thumbnail Image” field.
I think a better option could be to set the download item’s name/title as the alt tag since that information will be readily available on every install.
@mra13
A lot of users just enter an image URL from their amazon S3 account for example.
You have a strong point there. Hence, the function would be as shown:
// Simple Download Monitor: Add ALT attribute to download fancy 2 thumbnail
if ( is_plugin_active('simple-download-monitor/main.php') ) {
add_filter('sdm_download_fancy_2_thumbnail', function($thumb_output, $args) {
$download_id = $args['id'];
$download_thumb_url = get_post_meta($download_id, 'sdm_upload_thumbnail', true);
$download_thumb_alt = get_the_title($download_id); // get title instead of alt tag
$thumb_output = '<img src="' . $download_thumb_url . '" alt="' . $download_thumb_alt . '" />';
return $thumb_output;
}, 10, 2);
}