Dress codes vary in strictness depending on the policies of the golf course that you are playing. A good indicator of whether there is a dress code is the price of the course you plan to play. The higher the greens fees, the more likely there is to be a dress code for golfers.
In general, a collared shirt and Dockers-style shorts or slacks will get you onto most golf courses. Many lower-priced courses also permit denim shorts or even blue jeans.
But most upscale courses require collared shirts and have a no-denim rule. A very small number of (mostly private luxury) courses even have no-shorts rules, requiring golf slacks.
So how do you know whether you need to dress in slacks and wear a shirt with a collar? If you're planning on playing a course you've never been to before, and you're unsure of its dress code, call ahead. Don't assume - always call ahead. Golf courses will turn away golfers who show up without meeting the dress code (or you can choose to buy expensive pro shop golf apparel in order to bring yourself up to the course's standards).
Also, never assume that just because you've seen a professional golfer wearing a particular piece of clothing that the same clothing on you will pass muster at all courses. Again: call ahead and ask if you have any uncertainty. Otherwise, you might show up only to be told, "sorry, Tiger Woods can wear mock turtlenecks on the PGA Tour, but here you have to have a collar on your shirt." Or, "sorry, John Daly can wear those ridiculous pants on the PGA Tour, but you can't wear them here."
We know, a collar on a shirt doesn't sound like much, but if the course requires collars and you show up in a t-shirt, you'll either be buying a collared shirt in the pro shop or heading home.
As for golf shoes: Most golf courses have outlawed metal spikes. So make sure you're wearing golf shoes with softspikes or other non-metal golf cleats; or wear a soft-soled shoe of some other type (tennis shoes, for examples - never anything with a hard heel).
To recap: Yes, many golf courses - and most non-municipal courses - do have golf dress codes. If you wear a shirt with a collar and Dockers-style pants or shorts, you'll meet the dress code of 95 -percent of courses. But always call ahead before playing a new course and ask for the specifics.