Hi
I have a need to remove the link-to-image-node from an attached image in a page.

I have in my node.tpl.php:

print $node -> content['image_attach']['#value'];
print $node -> content['body']['#value'];

Is there someway to print $node -> content['image_attach']['#the_picture_without_link'] ??

Comments

trevor.eye9’s picture

Status: Active » Needs review

Hello,

I just ran into this problem today. I searched and searched with no luck on finding what I needed. The "Hidden Link" option on this image settings did not work. I came up with a solution by using str_replace and ereg_replace.

Place the following anywhere you want to print your image. I used it in node.tpl.php.

$replacement = $node->content['image_attach']['#value'];
$string = str_replace("</a>", "", $replacement);
$string = ereg_replace("<a[^>]*>", "", $string);
print $string;

Hope this helps.

UnicornSong’s picture

Hey thanks for that. I cant even remember which project i was trying to do this on, but I'll file that code away in my snippet library for next time.

Marko B’s picture

great! thanx, wonder which API function adds this link over image?! as in theme_image there is no link?!

rainer_f’s picture

There's also a longer discussion on #237275: Removing the href link from images that are in nodes. It would be fine to program a switch for this link into the admin interface of image.module.

drewish’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

leo.ruffini’s picture

Version: 5.x-1.2 » 6.x-1.0-beta5
Status: Closed (fixed) » Active

Hi,

I had added the following code to node.tpl.php to remove the link-to-image-node from attached images and it has been working fine for months but not anymore. I guess something has changed in one of the Image module upgrades that makes the solution obsolete, but I'm not a developer myself, so I'm quite lost.

Any ideas?

  <div class="content">
  <?php
$image_part = $node->content['image_attach']['#value'];
$string = str_replace("</a>", "", $image_part );
$string = ereg_replace("<a[^>]*>", "", $string);
$final_string=str_replace($image_part, $string, $content);

print $final_string;

joachim’s picture

Version: 6.x-1.0-beta5 » 5.x-1.2
Status: Active » Closed (fixed)

Please don't reopen age-old issues.

And secondly, whoever gave you that code, don't let them near your server again. Regexping html on the way to the browser is Bad Thing.

leo.ruffini’s picture

Sorry about that. I thought it was better to reopen an issue than to create a duplicate.

Regarding the code, if you take a look you'll see it's quite simmilar to the one posted in comment #1 of this issue (and that was another reason to reopen it, since it doesn't work anymore).

Having said that, I need a way to remove the link-to-image-node. Is there a way to do do it? I can open a new issue if it's better.

joachim’s picture

On second thoughts, as this is a support request rather than a bug, it's probably better to reopen rather than file a new one.

You need to get the latest dev of the module and override the theme function for attached images. You can simply change the bit that creates the link.

leo.ruffini’s picture

Version: 5.x-1.2 » 6.x-1.0-beta5
Status: Closed (fixed) » Active

OK, so as you suggest, I reopen it.

From your answer, I understand I have to override the image_attach module itslef.
Is that the best solution? I'm asking because that would require to re-edit it every time I upgrade Image to a newer version... What about overriding this in templete.php?

Anyway, I'd appreciate if you could be more precise on the change I need to do on the code, since I know little php.... What lines do I need to change?

Thanks.

joachim’s picture

> From your answer, I understand I have to override the image_attach module itslef.

No, override the theme function. Google it ;)

leo.ruffini’s picture

OK, I'll edit template.php. I know little php but I'll try. Any hint appreciated anyway.
Why do I need to use the latest dev instead of Beta , which I'm currently using?

joachim’s picture

> Why do I need to use the latest dev instead of Beta , which I'm currently using?

I made big changes to the image attach theming functions recently, and there's not been a beta release since. The dev is perfectly stable.

> Any hint appreciated anyway.

I'm afraid I don't have time to give support with things like theming in this issue queue. Someone else reading this issue might (and I'll leave it open for a bit); or you can try the forum or IRC.

joachim’s picture

Status: Active » Closed (fixed)

Several weeks since last post; closing.