Adding Meta Information to a Blogroll

I found a useful blog post on how to add text fields to the “link management” admin menu in WordPress:

But how do you save this information into your database?  This is a three step approach.

1.  Add the fields to you database:


function geo_blogroll_update_db(){
   global $wpdb;
   $wpdb->query("ALTER TABLE $wpdb->links ADD COLUMN link_city varchar(255);");
   $wpdb->query("ALTER TABLE $wpdb->links ADD COLUMN link_state varchar(255);");

2. Add text fields to the link admin screen:

add_action('admin_menu', 'add_geo_meta_to_links');

function add_geo_meta_to_links() {
   add_meta_box ('geo_link', 'Link Geography', 'geo_blogroll_form', 'link');

function geo_blogroll_form () {
  global $link;

<table class="form-table" style="width: 100%;" cellspacing="2" cellpadding="5">
  <tr class="form-field">
       <th value="top" scope="row"><label for="blog_city"><?php _e('City'); ?></label></th>
           <input name="blog_city" type="text" id="blog_city"
                  value="<?php echo $link->link_city; ?>" style="width: 95%" />
  <tr class="form-field">
    <th value="top" scope="row"><label for="blog_state"><?php _e('State'); ?></label></th>
      <input name="blog_state" type="text" id="blog_state"
             value="<?php echo $link->link_state; ?>"  style="width: 95%" />

<?php } ?>

3. And finally save this information to the database every time someone saves a new link or updates an old link:

add_action('edit_link', 'geo_blogroll_save_meta');
add_action('add_link', 'geo_blogroll_save_meta');

function geo_blogroll_save_meta ($link_id){
  global $wpdb;
  $sql_statement =  "UPDATE wp_links SET link_city='".$_POST['blog_city'].
                              "', link_state='".$_POST['blog_state'].
                              "' WHERE link_id =".$link_id.";";






One response to “Adding Meta Information to a Blogroll”

  1. Abi Avatar


    I’m Abi, an English SEO copywriter and content writer. I excel in crafting blogs, articles, e-commerce product descriptions, SEO content, website content, business service descriptions, newsletter content, brochures, proofreading, social media captions, LinkedIn content, and SOPs.

    My rate is USD 40 for every 1000 words of content. If you don’t have time to plan out your content, we can help you with that.

    Feel free to email me at with any current requirements.



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.