Remove Link from Image Attach in Drupal

Mar 1 2010

If you are using the Image Attach module in Drupal, you may not always want to have the image linked. Drupal links the image automatically to its own image node but sometimes you don't want that.

You can add an overide to your theme's template.php file. Note where it says 'your_theme' on line one, replace that with the name if your actual theme. You should also clear your Drupal cache after adding this code.

  1. function your_theme_image_attach_body($node, $iid) {
  2.   $img_size = variable_get('image_attach_size_body_'. $node->type, IMAGE_THUMBNAIL);
  3.  
  4.   if ($img_size != IMAGE_ATTACH_HIDDEN) {
  5.     drupal_add_css(drupal_get_path('module', 'image_attach') .'/image_attach.css');
  6.  
  7.     $image = node_load($iid);
  8.     if (!node_access('view', $image)) {
  9.       // If the image is restricted, don't show it as an attachment.
  10.       return NULL;
  11.     }
  12.     $class = 'image-attach-body' . ($image->status ? '' : ' image-unpublished');
  13.     $info = image_get_info(file_create_path($image->images[$img_size]));
  14.  
  15.     $output = '
  16. </p><div class="' . $class . '">';
  17.     $output .= image_display($image, $img_size);
  18.     $output .= '</div><p>'."\n";
  19.  
  20.     return $output;
  21.   }
  22. }


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

That was cool hack. I am not

That was cool hack. I am not a good programmer specially can't play with Drupal but give my most time to Wordpress. This image attach module was giving a lot pain in my a** :). Every image were being attached which should have been disabled to save. Anyway, now I can move to search for new hack to disable saving image from my website.
Facebook Application Analytics

Thanks for pointing out that function

That helped a lot. I had not found that function before but needed to get rid of the css that this function is adding to the HTML code:


$output = '';
$output .= l(image_display($image, $img_size), "node/$iid", array('html' => TRUE));
$output .= ''."\n";

Now, it's easy. And I agree with the previous commentator, that this should be somehow explained on drupal.org as part of the image attach functionality.

Thanks a lot, just what I was

Thanks a lot, just what I was looking for.
This should be in drupal.org

Fine

Thanks a lot! You are great.

This is the right one i`ve be searching a long time on the web.

It`s easy to implement and works fine.

Best regards from munich!
Axel

Great contribution

Thanks a lot, just what I was looking for.
This should be in drupal.org

Great contribution

Thanks a lot

Regards
W.Wallace

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.