If you want to remove links from images using functions.php in WordPress? Use following code in your theme’s functions.php file OR in site specific plugin.
1 2 3 4 5 6 7 8 9 10 11 12 | 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; } |
If you don’t care about non-attachment images and want all images within the post content to not be wrapped in links anyway, this should suffice:
1 2 3 4 5 | function attachment_image_link_remove_filter( $content ) { $content = preg_replace(array('{<a[^>]*><img}','{/></a>}'), array('<img','/>'), $content); return $content; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.