Created
November 15, 2013 11:05
-
-
Save iloveitaly/7482702 to your computer and use it in GitHub Desktop.
WordPress: Sets default image link to blank, removed all existing image links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: FixImageLinks | |
Description: Defaults image link to none, removes all existing image links which point to a wordpress upload | |
Version: 1.0 | |
Author: Michael Bianco | |
Author URI: http://github.com/iloveitaly/ | |
*/ | |
// http://andrewnorcross.com/tutorials/stop-hyperlinking-images/ | |
add_action('admin_init', 'iloveitaly_imagelink_setup', 10); | |
function iloveitaly_imagelink_setup() { | |
$image_set = get_option( 'image_default_link_type' ); | |
if ($image_set !== 'none') { | |
update_option('image_default_link_type', 'none'); | |
} | |
} | |
// remove image links: https://gist.github.com/mustabr/5366335 | |
add_filter('the_content', 'iloveitaly_attachment_image_link_remove_filter'); | |
function iloveitaly_attachment_image_link_remove_filter($content) { | |
$content = preg_replace( | |
array( | |
// "/media" for the roots theme | |
'{<a(.*?)(wp-att|wp-content/uploads|/media)[^>]*><img}', | |
'{ wp-image-[0-9]*" /></a>}' | |
), | |
array( | |
'<img', | |
'" />' | |
), | |
$content | |
); | |
return $content; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment