• Resolved Jack Holloway

    (@jack-holloway)


    My blog contains about 1000 images, each article features about 10 images. I wanted to add an active active one link (www.google.com for instance) after each image on my blog in every post and category. I made it in functions.php by inserting such thing:

    add_filter(‘the_content’, ‘superlink’);
    function superlink($content){
    $url = ‘google.com‘;
    $content = preg_replace (‘|<img.*?>|iu’, ‘$0’.$url, $content);
    return $content;
    }

    It works properly. But the thing is, I want to make this link appearing in only one category, so I made up this one:

    add_filter(‘the_content’, ‘superlink’);
    function superlink($content){
    if ( is_single() && in_category(‘1234’){
    $url = ‘google.com‘;
    $content = preg_replace (‘|<img.*?>|iu’, ‘$0’.$url, $content);
    }
    return $content;
    }

    …it doesn’t work. Where I have made an error? Hope you can help me out.

    Best,

    Jack

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Active link under every image in concrete category of my blog’ is closed to new replies.