In the automotive world, there's a popular notion that yellow muck behind the oil cover always signifies significant engine issues like a burst head gasket or sludge accumulation.
If you have other corroborating indicators, yellow gunk beneath the cap may imply that. However, it does not always mean you have these issues with your car. If you've simply went to add some oil or check, without noticing any other symptoms, it likely isn't a major issue but may be worth a further check.
Milky / Foamy: Possibly a blown head gasket or cracked engine.
Sludgy: Build up of deposits in the engine.
However, short drives with a cold engine can cause the same symptoms as a head gasket failure until the engine is properly warmed up.
If you've checked the dipstick and the inside of the valve cover and they're both normal, you can rule out an engine problem. The foamy / milky gunk is likely due to driving short distances.
Check the Dipstick
First, look for symptoms of a blown head gasket on the dipstick. When the head gasket between the cooling jacket and oil ports crack, coolant and oil combine in the crankcase and combustion chamber, forming a milkshake or pudding-like consistency in the oil.
That's not a good indication, and driving your car could end in possibly irreversible engine damage.
Other symptoms of a blown head gasket include the following.
Watery engine oil
Milky oil cap
Bubbling in coolant system
White smoke from exhaust
You don't have coolant seeping into the crankcase if the oil on your dipstick appears like regular golden brown or dark brown oil and is at the right level (assuming you have had regular service intervals).
Checking your dipstick for a milky or foamy appearance is a great way to tell.
Check Inside Engine
After that, shine a flashlight inside the valve cover (through the open oil cap) and inspect the valve springs and rocker arms. If it is clean and a metal colour then you don't have any sludge build up.
However, if there is dark brown or black deposits along with thick or congealed oil, you have sludge build up, which is carbon that has built up over time from lack of servicing, among other issues.
Short-Trip Gunk Build Up
Some gas and exhaust escapes the piston rings and enters the crankcase when the air/fuel combination ignites. This is known as blowby, and every engine has some degree of it.
Carbon monoxide, oxygen, and water are all present in the exhaust. The water develops into a pudding-like consistency when stirred into the crankcase oil. As you drive and warm up the engine, the water in the oil evaporates.
Short periods of driving, when the engine does not reach typical operating temperatures, the heated water and oil vapour rises to the top of the engine. The oil/water sits in the oil cap, generating a yellow gunk build up, since the oil filler cap is near the top of the cylinder head.
You can rule out an engine issue if you've checked the dipstick and the checked the interior of the valve cover and they're normal. The yellow gunk is natural and is created by driving short distances.
The idea is to either get the car out for longer journeys or to replace the oil more often.