PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, May 16, 2022

[FIXED] How to hide alt tag output on page?

 May 16, 2022     debugging, php, wordpress     No comments   

Issue

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 class="pexel-previous-post-data">
     
    <div class="pexel-previous-post-img">
        <a href="<?php echo $permalink; ?>">
            <img src="<?php echo $thumbnail; ?>" alt="<?php echo $image_alt; ?>" width="300" height="300">
        </a>    
    </div>
    
    <div class="pexel-previous-post-Text">
         <span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">&larr;</span> Previous', 'twentyeleven' ) ); ?> 
            <h5 class="pxl_head--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


Solution

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 );


Answered By - Suraj Sanwal
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing