If you are getting lot of 404 and soft 404 in Google webmaster tools, you can add this snippet to remove WordPress Post image links to solve. There are many weblogs, question answer forums tried to provide a snippet which works for all Theme Frameworks – including Genesis, Thesis, Woo and practically all, but most either never works or stops working after a version update of WordPress. Our Snippet To Remove WordPress Post Image Link (Image Link 404 Fix) Will Work With Any Theme And Forever. This precisely works with Genesis.
Remove WordPress Post Image Link (Image Link 404 Fix) : Why and Advantages
This falls among best practice for good WordPress websites. Linking to own post or the image is actually meaningless and not informative. We only need the image src
HTML output to insert the image. WordPress, unfortunately never provides an effective update with fixes bugs, issues of the old content – in other words, even if there is option to remove WordPress Post Image Link from the newer posts, there is no official way to remove the image links from older posts.
SQL Query is not a great way for full removal, as there can be need in future to get back to older condition within a snap. You should probably read Fix WordPress 404 Errors For Non Existing URLs to understand that – doing a 301 redirection towards the post or somewhere is not good to get rid off 404. Image, simply should not have any link unless you manually insert an image and then link it for definite reason.
---
Remove WordPress Post Image Link (Image Link 404 Fix) : The Snippet
You will need PHP prey replace
function :
1 2 3 4 5 6 7 8 9 10 11 12 13 | // add to active theme's function.php file // or child themes function.php file if exists function google_image_link_void( $content ) { $content = preg_replace( array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}', '{ wp-image-[0-9]*" /></a>}'), array('<img','" />'), $content ); return $content; } add_filter( 'the_content', 'google_image_link_void' ); |
This snippet will not change anything at backend, you will see post image links while editing the old posts. But this actually filter outs the HTML output. As it runs before W3TC or any Cache Plugin Works, once you have added and checked it from fronted, purge the cache and then clear the Cache. Remove all the post image related 404 from Google Webmasters tool and you will not get the error anymore. Try to hover over this post’s image, there is no link. If we change the snippet in use, we will update the post. We are good consumer of this snippet!
This is a practical way – it will not harm any links on category thumbnail or other images. If you manually change the image class in a post for some reason, obviously you will get the hyperlink working. This does not work (WP Beginner) for current version of WordPress :
1 2 3 4 5 6 7 | function wpb_imagelink_setup() { $image_set = get_option( 'image_default_link_type' ); if ($image_set !== 'none') { update_option('image_default_link_type', 'none'); } } add_action('admin_init', 'wpb_imagelink_setup', 10); |