WordPress: print_thumbnail outputting incorrect URLs. File permissions not making a difference

A site of mine – http://www.sweetrubycakes.com.au – has recently had the thumbnails stop working (they were working up until yesterday, yesterday the domain registrar had some issues, but nothing else I know of could have caused it).

If you view the source, you’ll see they include too much in the URL:

Read More
<img src="/home2/sweetrub/public_html/wp-content/uploads/et_temp/t-rex-tiny-63339_203x203.jpg" class="item-image" alt="T- Rexcellent">

where it should be:

<img src="/wp-content/uploads/et_temp/t-rex-tiny-63339_203x203.jpg" class="item-image" alt="T- Rexcellent">

I don’t think I’m using the most recent version of the theme, however I’ve made some tweaks and don’t wish to update.

The code that outputs that images is this:

<?php
   $work_count = 0;
   $recent_work_args = apply_filters( 'evolution_recent_work_args', array(
      'showposts' => (int) get_option('evolution_posts_work_num'),
      'category__not_in' => (array) get_option('evolution_exlcats_work')
   ) );
   $recent_work_query = new WP_Query( $recent_work_args );
   while ( $recent_work_query->have_posts() ) : $recent_work_query->the_post();
      ++$work_count;
      $width = apply_filters( 'evolution_home_work_width', 203 );
      $height = apply_filters( 'evolution_home_work_height', 203 );
      $titletext = get_the_title();
      $thumbnail = get_thumbnail($width,$height,'item-image',$titletext,$titletext,true,'Work');
      $thumb = $thumbnail["thumb"];
      $lightbox_title = ( $work_title = get_post_meta($post->ID, 'work_title',true) ) ? $work_title : $titletext;
      $work_description = ( $work_desc = get_post_meta($post->ID, 'work_description',true) ) ? $work_desc : truncate_post( 50, false );
?>
      <div class="r-work<?php if ( 0 == $work_count % 3 ) echo ' last'; ?>">
         <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, 'item-image'); ?>
         <span class="overlay"></span>
         <!--<a href="<?php the_permalink(); ?>" class="more"></a>-->
         <a href="<?php echo esc_url($thumbnail['fullpath']); ?>" class="zoom fancybox" title="<?php echo esc_attr( $lightbox_title ); ?>" rel="work_gallery" style="right: 77px !important;"></a>
         <p><?php echo esc_html( $work_description ); ?></p>
      </div> <!-- end .r-work -->
<?php endwhile; wp_reset_postdata(); ?>

And the print_thumbnail function looks like this:

if ( ! function_exists( 'print_thumbnail' ) ){
function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='') {
    global $shortname;
    if ( $post == '' ) global $post;

    $output = '';
    $thumbnail_orig = $thumbnail;

    $thumbnail = et_multisite_thumbnail( $thumbnail );

    $cropPosition = '';

    $allow_new_thumb_method = false;

    $new_method = true;
    $new_method_thumb = '';
    $external_source = false;

    $allow_new_thumb_method = !$external_source && $new_method && $cropPosition == '';

    if ( $allow_new_thumb_method && $thumbnail <> '' ){
        $et_crop = get_post_meta( $post->ID, 'et_nocrop', true ) == '' ? true : false; 
        $new_method_thumb =  et_resize_image( et_path_reltoabs($thumbnail), $width, $height, $et_crop );
        if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
    }

    if ($forstyle === false) {
        $output = '<img src="' . esc_url( $new_method_thumb ) . '"';

        if ($class <> '') $output .= " class='" . esc_attr( $class ) . "' ";

        $output .= " alt='" . esc_attr( strip_tags( $alttext ) ) . "' />";

        if (!$resize) $output = $thumbnail;
    } else {
        $output = $new_method_thumb;
    }

    if ($echoout) echo $output;
    else return $output;
}

}

I’ve seen some other posts that suggest that it’s a file permissions folder ( wp print_thumbnail function is not working ) but that doesn’t seem to be working for me.

Does anyone have any suggestions?

Related posts

Leave a Reply

1 comment

  1. I think print_thumbnail is the problem in your code. Instead of print_thumbnail try below options.

    <?php
    if ( has_post_thumbnail() ) {
        the_post_thumbnail(); // Outputs <img/> object with src="thumbnail-href"
    }
    ?>
    

    Similarly, this would also work:

    <?php
    if ( has_post_thumbnail() ) {
        echo( get_the_post_thumbnail( get_the_ID() ) );
    }
    ?>
    

    Check this stackoverflow answer