remove anchor element around Wordpress images with filter (or jquery) remove anchor element around Wordpress images with filter (or jquery) wordpress wordpress

remove anchor element around Wordpress images with filter (or jquery)


Find helpful code here:

Tried out, but caused invalid code.

Your code in ../your_theme/functions.php would look like this:

function remove_anchor($content) {    // the code for removing the anchor here    $content =        preg_replace(            array('{<a(.*?)(wp-att|wp-content\/uploads)[^>]*><img}', '{</a>}'),            array('<img',''),            $content        );    return $content;}// then use WP's filter/hook system like this:add_filter('the_content', 'remove_anchor');


Go into your WP theme's folder, edit "functions.php". Add code like this:

function remove_anchor($data){    // the code for removing the anchor here    // (not sure if you need help there, too).      // you will work on the $data string using DOM or regex    // and then return it at the end    return $data;}// then use WP's filter/hook system like this:add_filter('the_content', 'remove_anchor');

The add_filter means that every time a post is displayed, the remove_anchor function is called.

jQuery is probably easier, you just need to identify the images and not make them clickable (this is untested)

$(document).ready(function(){    $('#post a.some-class-name').click(function()    {        return false;    }});