• Resolved Evino

    (@evino)


    Hi

    Thanks for a great theme.

    I really need the images in posts to link to the post page instead of “link to itself”. When I click the image in the post i come to the domain/image.jpg – I simply want to see the single post instead.

    Thanks mate

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Silkalns

    (@silkalns)

    You can use WordPress built-in media manager to use a Custom URL that can point anywhere you want. You can read more about it here.

    Thread Starter Evino

    (@evino)

    Thanks for the answer

    I can only change one at a time that way, right? I have too many posts to do that… Is there any way to make all post-images link to the actual post?

    Thanks mate

    Theme Author Silkalns

    (@silkalns)

    It is possible using function like this:

    function sparkling_content_filter() {
      $content = get_the_content();
      $openpost = get_permalink();
    
      $body = preg_replace("{<img\\s*(.*?)src=('.*?'|\".*?\"|[^\\s]+)(.*?)\\s*/?>}ims", '<a href='.$openpost.'><img $1src=$2 $3/></a>', $content);
    
      return $body;
    }
    add_filter( 'the_content', 'sparkling_content_filter' );

    The only disadvantage is that once post is opened images will still point to that post because this filter works for the_content and it is used for both blog page and post pages.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Link image in post to the actual post’ is closed to new replies.