Insert link upon theme activation using wp_insert_link

Adding this snippet to the functions.php of your wordpress theme will add the specified link to your wordpress installation upon theme activation.

 

 

add_action("switch_theme","add_theme_link");
function add_theme_link() {
global $wpdb;
if($wpdb->get_var("SELECT COUNT(link_id) FROM $wpdb->links WHERE link_url='http://www.wpsnipp.com/'")==0)
wp_insert_link(array("link_name" => "WPSNIPP", "link_url" => "http://www.wpsnipp.com/" ));
}

Leave a comment