Home > Software engineering >  How to hide alt tag output on page?
How to hide alt tag output on page?

Time:05-01

Please check the screenshot, let me know how to fix this issue...And you can see there's no image alt data in HTML. Another thing is that if I use PHP in img src so I can't set width & height like (300 x 300). The output is a full-size image and if I use a static URL in img it works fine, how to deal with that?

<nav id="nav-single">
    <?php
        $prev_post = get_previous_post(); 
        $id = $prev_post->ID ;
        $permalink = get_permalink( $id );
        $thumbnail =  get_the_post_thumbnail( $id );
        $image_alt = get_post_meta($thumbnail, '_wp_attachment_image_alt', true);   
    ?>
    
    <div >
     
    <div >
        <a href="<?php echo $permalink; ?>">
            <img src="<?php echo $thumbnail; ?>" alt="<?php echo $image_alt; ?>" width="300" height="300">
        </a>    
    </div>
    
    <div >
         <span ><?php previous_post_link( '%link', __( '<span >&larr;</span> Previous', 'twentyeleven' ) ); ?> 
            <h5 ><a href="<?php echo $permalink; ?>"><?php echo $prev_post->post_title; ?></a>             </h5>
         </span>
    </div>

   </div>   
      
</nav>

enter image description here

enter image description here

CodePudding user response:

Use get_the_post_thumbnail_url() to get post image url as get_the_post_thumbnail() returns html with img tag. get_the_post_thumbnail_url() will return only image url.

 $thumbnail =  get_the_post_thumbnail_url( $id );
  • Related