WordPress.org

Ready to get started?Download WordPress

Forums

Style My Gallery
ALT text not being used (2 posts)

  1. thatwastaxing
    Member
    Posted 2 years ago #

    In FlexSlider, the code for using the alt text references the image title and not the alternate text supplied in the media library. How can I change this?

    http://wordpress.org/extend/plugins/style-my-gallery/

  2. thatwastaxing
    Member
    Posted 2 years ago #

    To properly show the alt text, open style-my-gallery.php and replace:

    /**
    		* Add images
    		*/
    		$i = 0;
    		foreach ( $attachments as $id => $attachment ) {
    			$image 		= wp_get_attachment_image_src($id, $size);
    			/* Switch to relative path for Imageflow */
    			if ($style == 'ImageFlow') {
    				$longdesc = $image[0];
    				//$image[0] = str_replace(get_bloginfo('url'),'../../../..',$image[0]);
    			}
    
    			if ($style == 'FlexSlider') $output .= '<li>';
    			$output .= '<img src="' . $image[0] . '" alt="' . $attachment->post_title . '" ';
    			if ($style == 'ImageFlow') $output .= 'width="' . $image[1] . '" height="'. $image[2] . '" longdesc="' . $longdesc . '" ';
    			$output .= '/>' . PHP_EOL;
    			if (($style == 'FlexSlider') && ($attachment->post_content != '')) {
    				$output .= '<p class="flex-caption">' . $attachment->post_content . '</p>' . PHP_EOL;
    			}
    			if ($style == 'FlexSlider') $output .= '</li>' . PHP_EOL;
    
    			/* build separate thumbnail list for users with scripts disabled */
    			$noscript .= '<img src="' . $image[0] . '" width="100px">' . PHP_EOL;
    			$i++;
    		}

    With:

    /**
    		* Add images
    		*/
    		$i = 0;
    		foreach ( $attachments as $id => $attachment ) {
    			$image 		= wp_get_attachment_image_src($id, $size);
    			$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    			/* Switch to relative path for Imageflow */
    			if ($style == 'ImageFlow') {
    				$longdesc = $image[0];
    				//$image[0] = str_replace(get_bloginfo('url'),'../../../..',$image[0]);
    			}
    
    			if ($style == 'FlexSlider') $output .= '<li>';
    			$output .= '<img src="' . $image[0] . '" alt="' . $alt . '" ';
    			if ($style == 'ImageFlow') $output .= 'width="' . $image[1] . '" height="'. $image[2] . '" longdesc="' . $longdesc . '" ';
    			$output .= '/>' . PHP_EOL;
    			if (($style == 'FlexSlider') && ($attachment->post_content != '')) {
    				$output .= '<p class="flex-caption">' . $attachment->post_content . '</p>' . PHP_EOL;
    			}
    			if ($style == 'FlexSlider') $output .= '</li>' . PHP_EOL;
    
    			/* build separate thumbnail list for users with scripts disabled */
    			$noscript .= '<img src="' . $image[0] . '" width="100px">' . PHP_EOL;
    			$i++;
    		}

    This will properly display the images alt text rather than showing the attachment title.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic