-
-
Save oluwabajio/a4410830d4f2f4ed4ce15625a864c496 to your computer and use it in GitHub Desktop.
WordPress plugin to remove all bit.ly links from post content, keeping the anchor text
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: Remove bit.ly links | |
Description: Plugin to remove all bit.ly links from post content, keeping the anchor text. | |
Version: 1.0 | |
Author: Matthias Kretschmann | |
Author URI: http://mkretschmann.com | |
*/ | |
// Filter the_content | |
add_filter('the_content', 'rbl_remove_bitly_links'); | |
// Le function | |
function rbl_remove_bitly_links($content) | |
{ | |
// Regex, FTW! | |
// Search & remove link markup for all links | |
// with bit.ly, j.mp or bitly.com as href attribute | |
return preg_replace('@<a[^<>]*href="(?:http://|https://)(?:bit\.ly|j\.mp|bitly\.com)[^"]*"[^<>]*>@Uis', '', $content); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment