There are a few ways to do this. Note that all of the following methods require software modification unsupported by Nintendo that have the possibility of damaging your console and voiding your warranty - they must be done at your own risk.
The most popular replacement online server for Nintendo WiFi Connection is Wiimmfi, which has about 400 players online at any given time. In order to access this server, a custom DNS server must be used and/or games must be patched in order to connect to this separate server. If you had a friend code from Nintendo WiFi Connection, a new code will automatically be generated for you when you first connect to Wiimmfi.
There are several methods you can use to connect to Wiimmfi.
Method 1: Custom DNS (easiest, Wii and Wii U, no custom tracks)
Requires: Nintendo Wii or Wii U with Internet Connection
All you need to do is set your Wii/Wii U internet connection's primary DNS to 220.127.116.11 (and secondary DNS to any other valid DNS server, such as 18.104.22.168) in your Wii/Wii U's network settings. This only has to be set once. Then, any time you want to play online, all you need to do is launch the game you want to play. Only a few games, including Mario Kart Wii, are supported by this method. A video tutorial is available for this method.
Method 2: Custom DNS and View EULA (easy, Wii ONLY, no custom tracks)
Requires: Nintendo Wii with Internet Connection
This method supports more games than the previous one, but a patcher has to be run each time you want to play online. All you need to do is set your Wii internet connection's primary DNS to 22.214.171.124 (and secondary DNS to any other valid DNS server, such as 126.96.36.199) in your Wii's network settings. Then, any time you want to play online, all you need to do is go into the Wii's network settings and view the EULA/User Agreement. A video tutorial is available for this method.
Method 3: Internet Channel (easy, Wii ONLY, no custom tracks)
Requires: Nintendo Wii with Internet Connection, Internet Channel installed
You can use the Internet Channel to launch a Wiimmfi patcher by navigating to http://chadsoft.co.uk/wiimmfi/ and adding this page to your bookmarks. Each time you want to be able to connect to Wiimmfi, you must run this exploit by using the bookmark in the Internet Channel (it must be run by clicking on the bookmark).
I strongly suggest that you watch this video for the full directions.
Method 4: CTGP-R [Custom Track Grand Prix - Revolution] (intermediate , Wii and Wii U, custom tracks)
Requires: Nintendo Wii or Wii U with internet connection, SD card, computer or Android phone capable of writing to SD cards, unzipping files, connecting to the Internet
CTGP-R is a mod for Mario Kart Wii that will also let you play online, with enhancements such as VR matching and cheat prevention.
In addition to the 32 original tracks, it adds 216 custom tracks to the game, an item rain mode (items fall from the sky), a countdown mode (hit others with points to get more time to race, farthest ahead wins), a new time trial ghost server with cheat detection, a cup organizer, an option to store the game’s save file on the SD card, regular automatic updates that change custom tracks and add new features, automatic friend code update for Wiimmfi, as well as other features. Unfortunately, you cannot play battle mode while running this mod with custom tracks enabled within the launcher settings.
CTGP-R is harder to install, but works on both Wii and Wii U.
Methods vary by system and software version.
This video is a tutorial for installing CTGP on Wii version 4.3.
This installation guide has written instructions for all system versions of Wii and Wii U.
It is also possible to play competitions/tournaments on Wiimmfi, but that requires a separate patcher. Information can be found on the Wiimmfi website.
Any error codes you get from Wiimmfi can be looked up here: https://wiimmfi.de/error.
Remember that using Wiimmfi requires software modification that could void your warranty, so do it at your own risk.