0

Bit.ly have black listed one site which i linked to which produces a warning.

I have removed this link but want to remove all links which i have shortened using Bit.ly

Is this possible?

2
  • edit, the question is actually kind of difficult to understand. You should re-word it, that's probably why you were downvoted.
    – wordpress
    Jun 19, 2012 at 13:00
  • the main question is good but the body is too hard to understand. Sorry, I can't answer this.
    – wordpress
    Jun 19, 2012 at 13:01

1 Answer 1

1

This can be solved by making SQL queries directly in the database. But this only works easily for replacing the URL of a link, not the whole link markup. Replacing all bit.ly links with their original long URL would be the best way to solve the blacklist problem. This is the query you would do, for example in phpMyAdmin or whatever you're using to access your database:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://bit.ly/oldlink', 'http://newlink.com/newlink');

But if you want to completely remove the link so that only the anchor text remains, there's not much you can do except regex filtering the content with preg_replace:

<?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);
}

This looks for all domains bitly is using, feel free to reduce that to the set you need. You can put this into a new php file in your wp-content/plugins folder and activate it. A more lazy way would be to add this to your theme's functions.php file.

Please be aware this won't really remove the links from the database, so they will still be visible in the editor. They just won't appear on the frontend.

6
  • I was thinking about removing them using notepad++. I have a sql dump which i could use to easily remove them but not sure if it would remove the anchor text.
    – user16465
    Jun 19, 2012 at 20:49
  • When i put this file into my child themes functions file my site went white and got a 500 error. I guess it would be best to remove this beforehand: <?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: mkretschmann.com */
    – user16465
    Jun 22, 2012 at 12:38
  • Be sure to not include "<?php" if you already have an existing functions.php where this is already present. That's why my first recommendation was to use this as a plugin. Jun 22, 2012 at 14:05
  • worked fine after i added it to my child themes functions.php and removed <?php
    – user16465
    Jun 23, 2012 at 14:34
  • Brad, great to hear. Although not perfect because the links are still in the database, I think this is the best solution if you don't want to edit the links one by one manually. Jun 25, 2012 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy