ALT tag in featured image


  • Member
    drunkfox
    November 24, 2017 at 6:51 pm #32277

    Hi there,
    I’m here again to try to resolve this “problem”.
    In the past I asked your support for the same question, and it looks I was able to fix it, but now I realize that I did not.
    Please may you help me? I spended all the day trying to insert the ALT tag in post featured images, but I’m don’t know php language and I failed 1000 times :-(
    In my old post you said:
    Yes, you need to edit your index.php and single.php templates, then find all occurences of “wp_get_attachment_image_src”
    Then add the params for the alt tabs as described here:

    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

    Then add the alt attribute to the image below.
    I tried to edit the files index.php and single.php, but no success…
    Below is just a part of the code that I need to edit… How to add the params for the alt tab?

    <?php // IF Post type is Standard (false) 	
    			if(function_exists( 'get_post_format' ) && get_post_format( $post->ID ) != 'gallery' && get_post_format( $post->ID ) != 'video' && has_post_thumbnail()) { 
    					$thumbbig = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'portfolio-full' );
    					$attachment_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'portfolio-main');
    		?>
    						<div class="pic">
    							<a href="<?php echo $thumbbig[0];?>" rel="prettyPhoto" title="<?php echo $post->post_title; ?>">
    								<img src="<?php echo $attachment_image[0];?>" /><div class="img_overlay_zoom"></div>
    							</a>
    						</div>
    						
    						
    						<div class="h20"></div>	
    		
    		<?php } // IF Post type is Standard :: END ?>
    		
    		<?php // IF Post type is Gallery
    		if (( function_exists( 'get_post_format' ) && get_post_format( $post->ID ) == 'gallery' )) {
    					$args = array(
                                'numberposts' => -1, // Using -1 loads all posts
                                'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
                                'order'=> 'ASC',
                                'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
                                'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
                                'post_status' => null,
                                'post_type' => 'attachment'
                                );
    
    					$images = get_children( $args );
    					
    					if($images){ ?>
    					
    					<div class="flexslider">
    				        <ul class="slides">
    						<?php foreach($images as $image){ 
    								$attachment = wp_get_attachment_image_src($image->ID, 'portfolio-full');
    								$thumb = wp_get_attachment_image_src($image->ID, 'portfolio-main'); 
    						?>
    								<li class="pic">
    										<a href="<?php echo $attachment[0] ?>" rel="prettyPhoto[gallery]" title="<?php echo $image->post_title; ?>" >
    											<img src="<?php echo $thumb[0] ?>" /><div class="img_overlay_zoom"></div>
    										</a>
    								</li>
    						<?php } ?>						
    						</ul>  
    					</div>

    I hope you can help me, alt tag is important for SEO…
    Ciao.
    Enrico

    Sorry, this forum is for verified users only. Please Login or Register to continue

Comments are closed.