Removing the link of image in WordPress attachment page

Last updated on June 9, 2010. Tags: , ,

Whenever you embed an image to your post or static page, a small window will appear at the center and darken the rest of your dashboard. You're then prompted to either download the image or select from among those you already downloaded (media library). Then you will be prompted to configure it in a certain manner like encoding the title attribute, alt text and link URL - the link to which you will be forwarded when you click on the image.

Under the link URL, you have three quick options: none, file URL and post URL. None means your image will just be a simple embedded image and not a hyperlink. File URL will link the image to its actual URL (or the URL of its full size in case you didn't choose "full size" under the size option) and you will see the image alone in your browser window. Post URL will link the image to an attachment page, wherein you will see a page similar to the post and static page of your theme, but it contains only the image and nothing else.

wordpress add image option

By default, the attachment page will display the "medium" size of the image (the size options thumbnail, medium and large can be configured in Settings ยป Media, full size is the actual image size) and this medium size image, in turn is a hyperlink to the actual URL of the full size image. To change the default medium size, click here. For this post, we will deal with the default hyperlink image in the attachment page.

Suppose you don't want this image to be a hyperlink. Maybe you do not want the image to be seen without the look and feel of your site. Perhaps, the idea of having a large solo image on a page and still being a hyperlink does not appeal to you. Whatever your reason, you can make the attachment page display only that image without it being a hyperlink.

Unfortunately, this option is not available in the Dashboard. You need to do some code tweaking to implement this.

First, you need to open post-template.php using the text editor provided in your hosting account (or download and open it using notepad). You can find it in the /wp-include/ folder in your root directory, or in whatever folder you installed WordPress.

Then, look for the line:

return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text );

Delete the entire code above and replace it with the following:

if (is_attachment())
{return apply_filters( 'wp_get_attachment_link', "$link_text", $id, $size, $permalink, $icon, $text ); }
else
{return apply_filters( 'wp_get_attachment_link', "<a href='$url' title='$post_title'>$link_text</a>", $id, $size, $permalink, $icon, $text ); }

Then save it, or if you are using notepad, save it and upload it and overwrite the original file.

That's it. If you have an attachment page, you can refresh it and you will see that the image embedded or it is no longer a hyperlink. If you have none, then upload an image and select the post URL option. The image embedded on the page or post is a link to an attachment page. The image on the attachment page, however, is no longer a link.

Important notes:

Posted by Greten on June 8, 2010 under WordPress tweaks

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • StumbleUpon
  • Technorati

Related Posts

You might also be interested (randomly generated):

Post Comments

Please double check your comment before clicking the "Post" button. Once you clicked it, there will be no way for you to edit your comment.





* Required. Your email will never be displayed in public.