I have a plugin that I use on all my new sites to set up site defaults (deletes the "hello world" post, the "about" page, the "Mr WordPress" comment, etc...)

I'd like to add a routine that removes all the default links under "Blogroll". I'm not sure what function to call. Any ideas?

2 Answers 2


Haven't tested this yet, but it should do the trick in 3x:

// Get all the existing links
$arr_args = array( 'hide_invisible' => 0 );
$arr_links = get_bookmarks( $arr_args );

// Run through the list and delete 'em
foreach($arr_links as $obj_link) {

Of course, you'd only want to do this once, and only on a fresh install as it deletes all links. Alternately, you could hardcode an array of default link slugs/ids and loop through that instead. Depends where and when you're running this thing.


Just "truncate wp_links" using wpdb. :-)

  • +1 - but don't forget about the term relationships first (and possibly even deleting the term 'blogroll' too?) Dec 6, 2010 at 22:09
  • 1
    Denis, sounds interesting, can you elaborate a bit on how you would do this taking TheDeadMedic's comment into account?
    – Scott B
    Dec 6, 2010 at 22:41
  • 1
    Why would you mess with all this manually when Wordpress has a native function for deleting links? The function wp_delete_link() deletes a link and its relationships for you. It also cleans out the bookmark cache.
    – MathSmath
    Dec 6, 2010 at 23:38
  • 1
    @MathSmath It was only that a raw query does everything in one swoop - but in hindsight, you're right. I'd combine the two solutions, wp_delete_link() to clear out the cache and term relations, then TRUNCATE to reset the table index :) Dec 6, 2010 at 23:52
  • @TheDeadMedic Digital high five.
    – MathSmath
    Dec 7, 2010 at 1:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.