Remove image links in Posts on WordPress

Here is how to easily remove image links in posts on wordpress blogs. Many of you might have seen on our blog that when you click on any image in a post it doesn’t go anywhere (i.e. it is not linked to anything).

By default, wordpress links the images in a post to its url page (or attachment page). We have already discussed the right way of linking images in your posts.

Read: How To Link image to Parent Post Page in WordPress

Now lets see how we can disable the linking of images completely. Remember this tutorial doesn’t disable the right click on images (which is not SEO friendly), people can still copy your images.

Just drop this function in your functions.php file:

/** Remove image links in posts */
add_filter( 'the_content', 'attachment_image_link_remove_filter' );
function attachment_image_link_remove_filter( $content ) {
 $content =
 preg_replace(
 array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}',
 '{ wp-image-[0-9]*" /></a>}'),
 array('<img','" />'),
 $content
 );
 return $content;
 }

Press the Update file button and you are all done. Just check by visting one of your blog posts and refreshing the page. Now try clicking on any of the images, you can’t! The mouse cursor doesn’t appear itself.

NOTE: By using this function, you are disabling wordpress’s image linking feature. You can no longer link any of the images in your posts.

By doing this you are:

1. Providing a good user experience as people are not getting directed to another page (thereby reducing site bounce rate).

2. Spammers cannot quickly copy your images.

3. Handling your site seo systematically, as search engine bots cannot crawl the url of the attachment page.

4. Reducing your reader’s level of distraction, as they can’t click on your images.

5. Lessens the amount of broken links on your site

Let us know if this tutorial on how to remove image links in posts on wordpress helped you? Let us know your thoughts on this, and please don’t forget to subscribe to our newsletter for further such tutorials.

Source: WPMU

Subscribe to our Weekly Newsletter

I take your privacy very seriously

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail.