Home / admin / Insert link upon theme activation using wp_insert_link
  • How to Insert link upon theme activation using wp_insert_link

    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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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/" ));
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    switch_theme, add_action, _n, wp,