• Resolved pyrrho

    (@pyrrho)


    I want the first image in a post to automatically link to the ‘post page’ (the full article), but so far, I haven’t been succesful.

    I installed the Post Image plug-in from Guff, but I am having some trouble with it. If I put this in the loop…

    <?php post_image(); ?>
    <?php the_content('>>>'); ?>
    <?php edit_post_link('Edit article', ''); ?>

    …I see the image TWO times. The first image DOES link to the full article, but it is placed at the wrong position (above the text).

    Maybe somebody could share some tips?

Viewing 6 replies - 1 through 6 (of 6 total)
  • I once faced the same dilemma ^_^.

    Here is the code that I came up with:

    function link_image($content){
    
    $searchfor = '/(<img[^>]*\/>)/';
    $replacewith = '<a href="'.get_permalink().'">$1</a>';
    
    if (is_single() === FALSE){
    	$content = preg_replace($searchfor, $replacewith, $content, 1);
    }
    return $content;
    
    }
    
    add_filter('the_content', 'link_image');

    Copy and paste that code into your functions.php file, and you’re all set.

    Cheers!

    Thread Starter pyrrho

    (@pyrrho)

    Thanks for your code! I get an error, though:

    Call to undefined function: add_filter() in …/wp-includes/functions.php on line 15

    Any idea how to define the add_filter function?

    you’re putting the line into the wrong functions.php.

    you neeed to put that into a functions.php in your THEME folder. If there isn’t already an existing functions.php there, make one.

    Dynamic duo out.

    Thread Starter pyrrho

    (@pyrrho)

    That was… very stupid. 😉

    Thank you very much (wp_guy AND Ivovic). It works!

    That’s actually quite an elegant solution, I’m gonna have to make a note.

    *tips hat to wp_guy*

    Thanks 😎

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Permalink in FIRST image?’ is closed to new replies.