Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have try over a week to validate 4 images that are retrieved by a code with GD Star Rating plugin

This is the code i have:

wp_gdsr_render_rating_results(array('template_id' => 49, 'rows' => 4, 'select' => 'post', 'hide_empty' => false, 'min_votes' => 0, 'min_count' => 0, 'excerpt_words' => 0, 'image_from' => 'custom', 'image_custom' => 'img', 'image_resize_x' => 72, 'image_resize_y' => 80,  ));

So the output look's like this:

enter image description here

I dig on google and I modify the code to get me the poster by a custom field.

This I add to retrieve the picture from a custom field.

foreach ($all_rows as $row) {
    if ($widget["image_from"] == "content") {
        $row->image = gdFunctionsGDSR::get_image_from_text($row->post_content);
    } else if ($widget["image_from"] == "custom") {

    $post_custom_id = get_post_meta($row->post_id, $widget["image_custom"], true);

        $row->image = get_bloginfo('url')."/scripts/timthumb.php?src=".get_bloginfo('url')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&h=70&w=55&zc=1";
     else if ($widget["image_from"] == "trailer") {
        $post_custom_id = get_post_meta($row->post_id, $widget["image_trailer"], true);// getVideoId is a custom function
        $row->image ="http://img.youtube.com/vi/".$post_custom_id ."/0.jpg" ;

    } else $row->image = "";

    $row->image = apply_filters('gdsr_widget_image_url_prepare', $row->image, $widget, $row);

    if ($row->image != "" && intval($widget["image_resize_x"]) > 0 && intval($widget["image_resize_y"]) > 0) {
        $row->image = GDSRRenderT2::prepare_image($row->image, $widget["image_resize_x"], $widget["image_resize_y"]);


This is the original code line 139


The code I added is :

$row->image = get_bloginfo('url')."/scripts/timthumb.php?src=".get_bloginfo('url')."/wp-content/uploads/".get_post_meta($post_custom_id,"_wp_attached_file",true)."&h=70&w=55&zc=1";

So the question how can I add to the images the alt attribute to display in the html page.

The error i get in http://validator.w3.org is

Line 580, Column 195: An img element must have an alt attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.

share|improve this question
Can you show how you are displaying image markup? –  Vinod Dalvi Apr 18 '13 at 4:58
i'm not understand wath you are refering... Vinod.. –  Batman Apr 19 '13 at 10:33
nobody knows how to corect this? –  Batman Apr 21 '13 at 20:32
add comment

1 Answer

Add the attribute to each line of code that creates an img tag. In your text editor, search for lines that contain the string "<img".

Lines 241 and 273:

$row->item_trend_rating = sprintf('<img class="trend" src="%s" style="%s" width="%s" height="%s"></img>', $gdsr->e, $image_bg, $set_rating->size, $set_rating->size);


$row->item_trend_rating = sprintf('<img class="trend" src="%s" style="%s" width="%s" height="%s" alt="%s"></img>', $gdsr->e, $image_bg, $set_rating->size, $set_rating->size, 'ALT TEXT HERE' );

Change ALT TEXT HERE to the text you want to use here.

Line 503:

$rater_stars = '<img src="'.STARRATING_URL.sprintf("gfx.php?type=thumbs&value=%s", $score).'" />';


$rater_stars = '<img src="'.STARRATING_URL.sprintf("gfx.php?type=thumbs&value=%s", $score) . '" alt="' . $score . '" />';

Lines 506 and 511:

$rater_stars = '<img src="'.STARRATING_URL.sprintf("gfx.php?value=%s", $rating).'" />';


$rater_stars = '<img src="'.STARRATING_URL.sprintf("gfx.php?value=%s", $rating) . '" alt="' . $rating . '" />';

I used $rating as the alt text because it looks like a string. Feel free to change it.

share|improve this answer
sorry but is not working.. no alt atribute is show in html –  Batman Jul 20 '13 at 16:33
Did you check for typos (using WordPress debugging)? –  Charles Clarkson Jul 22 '13 at 1:00
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.