When you upload an image inside your WordPress blog’s post, it becomes clickable. Let’s remove the link behind an image automatically so that, images inside the post doesn’t remain clickable anymore.

Why one needs this?

Have you ever heard about the word ENGAGMENT? Yes or No? Let me tell you when a visitor clicks an image inside your WordPress blog’s Post, that particular image shows up(With nothing else at that link) which makes the visitor close the tab and move away. What happens with that?

Why that bad?

  • You start loosing your visitors
  • Your site’s bounce rate increases
  • Avg time of per visit decreases.

How to tackle this problem?

Goto your WordPress blog’s Admin panel and move to Appearance Tab >> Then Editor >> After that select Functions.php from the right side bar. Add the following code at its end, and then click Update

 update_option( 'image_default_link_type', 'none' );
 function no_atag_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content); }
add_filter('the_content', 'no_atag_on_images');   

What this code will do?

It will remove a tag from every image you upload & include in the post. Like the image below has only img tag and no a tag.

no a tag image

FAQ

What about my old posts?

They will remain unchanged.

How will I add link to an image if I intentionally want to add one?

This code will not stop you from adding links manually to a blog post’s image. But one thing you can stay sure of is it will  not allow automatic links to be included.

What if I want to add the image link to the image?

When you are about to insert the image in the post click File URL once :)

Screenshot 1 image

Advertisement

Your Turn:

  • Did you like the tutorial?
  • How much it affected your engagement?