function connect_another_db() { global $seconddb; $seconddb = new wpdb(USERNAME, PASSWORD, DATABASE_NAME, HOSTNAME); } add_action('init', 'connect_another_db');