• I’m trying to make a custom download button for my single posts, so I added the following code in my single.php

    <div id="downloadbutton">
      <?php if(get_post_meta($post->ID, "download_link", $single = true) != ""){ ?>
      <a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"<img src="example.png" border="0"></a>
      <?php } ?>
    </div>

    For some reason, the download button shows up only in Firefox browser, but not in Chrome or IE…

    Any tips?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Bei337

    (@bei337)

    Found the problem:

    The tag wasn’t properly closed. So it should be like this instead:

    <a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"><img src="example.png" border="0"></a>

    You did not close the img tag or add the alt tag, so would fail validation!

    <a href="<?php echo get_post_meta($post->ID, "download_link", $single = true); ?>"><img src="example.png" border="0" alt="Download File" /></a>

    You could tidy the code and hide the button if there is no download, add width and height style to optimize the image load

    <?php if( get_post_meta( $post->ID, 'download_link', true ) ): ?>
    	<div id="downloadbutton">
    	  <a href="<?php echo get_post_meta( $post->ID, 'download_link', true ); ?>"
    	  <img src="<?php bloginfo('template_directory'); ?>/images/download.png" style="width:100px; height:32px;" border="0" alt="Download File" /></a>
    	</div>
    <?php endif; ?>

    HTH

    David

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘This short PHP code works in Firefox but nothing else?’ is closed to new replies.