• Hello, I am trying to set a custom link to the featured image, where if someone clicks on the featured image it would take them to any url I assign (such as an affiliate link). However, when they click on the post title, it will take them to that post inside wordpress. A good example of this is https://www.thisiswhyimbroke.com/

    I am using a free wordpress theme and I know that you can set up a custom field to put the desired url but I don’t know how to write or where or how to change the code to the theme’s funcitons.php. Here’s the function php for the theme:

    <?php
    
    if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
      add_theme_support( 'post-thumbnails' );
      add_image_size('featured-big',335,338,true);
      add_image_size('featured-medium',284,176,true);
      add_image_size('featured-small',240,250,true);
      add_image_size('featured-sidebar',58,58,true);
      add_image_size('featured-blog',336,157,true);
    }
    
    if ( function_exists('register_sidebar') ) {
            register_sidebar(array(
                    'name'=>'Sidebar Top',
    		'before_widget' => '<div class="sidebar_box">',
    		'after_widget' => '</div>',
    		'before_title' => '<h3>',
    		'after_title' => '</h3>',
    	));
    }
    
    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
    
      if(empty($first_img)){ //Defines a default image
        $first_img = "/images/post_default.png";
      }
      return $first_img;
    }
    
    function kriesi_pagination($pages = '', $range = 2)
    {
         $showitems = ($range * 2)+1;  
    
         global $paged;
         if(empty($paged)) $paged = 1;
    
         if($pages == '')
         {
             global $wp_query;
             $pages = $wp_query->max_num_pages;
             if(!$pages)
             {
                 $pages = 1;
             }
         }   
    
         if(1 != $pages)
         {
             echo "<div class='pagination'>";
             if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
             if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
    
             for ($i=1; $i <= $pages; $i++)
             {
                 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
                 {
                     echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
                 }
             }
    
             if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";
             if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
             echo "</div>\n";
         }
    }
    
    ?>

    Would appreciate any help! Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to set a featured image to an external url’ is closed to new replies.