There is a 99% chance that your 4WD is not working because your front axle disconnect is not working. Let me explain what this means. On a YJ, you have the transfer case that actually does all the work of transferring power to the front axle when you're in 4WD. However, Jeep also added a vacuum-powered disconnect on the passenger side of the front axle that has a shift fork and an axle collar ring. It is supposed to activate when you shift the t-case into 4WD, and the vacuum motor pushes the shift fork, which slides the axle collar into the 'engaged' position, and presto, now your front axle is engaged and you have 4WD. The 4WD light on the dash (if you have it) is also operated by this system; if it's not coming on when you shift into 4WD, it means your vacuum disconnect is not working.
There are a few ways you can fix this. All of them are painfully easy, and a mechanic will not be necessary unless you have severe tool phobia or something.
Option A: Buy and install the PosiLok cable. This is the best way but also the most expensive.
4X4 Posi-Lok Jeep Driveline Parts - Quadratec
Option B: Replace the axle disconnect vacuum motor, shift fork, and associated vacuum lines. This is cheaper now but could be prone to failure again in the future, unlike the PosiLok.
Original Replacement Parts 83503113 - Vacuum Motor for 87-90 Jeep® Wrangler YJ - Quadratec
Original Replacement Parts 83503695K - Replacement Shift Fork Kit for 87-95 Jeep® Wrangler YJ, 84-91 Cherokee XJ & 86-91 Comanche MJ - Quadratec
You can get the vacuum lines at your local auto parts store for next to nothing.
Option C: Unbolt the disconnect housing, turn it 180 degrees, and bolt it back on reversed. This flips the shift fork's disengaged position so that it is always engaged. This is the cheapest fix because it doesn't cost you anything if you have a socket set. The only drawback is that the front driveshaft will now turn all the time, even when in 2WD. This will add a little vibration at speed because the front driveshaft is not balanced from the factory. Still, this is what I did and the added vibration has been barely noticeable. I took a 150 mile trip on the interstate doing 65 - 70mph most of the trip and I never noticed it. I haven't noticed a loss in fuel economy either.