Support » Fixing WordPress » Change image “link to” to ‘none’ – globally?

  • We have hundreds of posts on our site, each with many photos. We have changed themes a couple times and somewhere along the line, the “link to” has changed to “media file” on many of the photos! We want them to be all on “none” I have searched the internet for a solution to change them all back to “none” and only found info on how to change on new images added going forward. There is no way we could go thru and change each one manually. It would take for-ever! Is there a plug-in or some solution that will change all the photos in all the post to “none”? If not is there a way to go into the database and do that?
    I hope you can help!

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • I do not a plugin. Directly adjusting the database is, I think not possible for that.

    I would go through every post, searching the content for a elements. If found check if there is an img within. If so remove a element and replace with the img found.

    This requires good PHP knowledge though.

    Hi sb12759,

    Add below code to your theme function.php file.

    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]*” />}’),
    array(‘<img’,'” />’),
    $content
    );
    return $content;
    }

    Thanks @ketanambaliya !
    What exactly does this do? Over-ride any selection for the image ‘link to’
    Will this change all the existing images to “link to – none”? Or just the new images added going forward?

    Thanks!

    Oh sorry – and does it matter where in the function.php file it should go?

    It will remove link from existing images.

    You can add anywhere in function.php

    @ketanambaliya

    That didn’t seem to work! Didn’t change anything and then I got a notification that the site was down from ‘site sensor’ so I took out the code right away.

    Any other ideas?

    Thanks!

    sb12759

    (@sb12759)

    Can anybody help? Does anybody from wordpress read these questions? Seems like there should be a solution for this!

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Change image “link to” to ‘none’ – globally?’ is closed to new replies.