Head retention is its own special science. Ph.D.s have been earned on the subject. The thing to keep in mind is that the molecules that form head do so only once. Then they're done.
First, eliminate the common things that are foam negative:
Oils/soap residues
pH above 4.7 (finished beer)
pH below 3.8 (finished beer)
hot break
low CO2 lamination
Excessive foaming, churning during fermentation and bottling.
Repeated gassing and degassing kegged beer.
Oxidation
Unclean glassware
High ethanol level
Low ethanol level (the optimum is right around 4.5 to 5.5% abv)
High amounts of fusel alcohols
I find that carafoam malt does an excellent job, better than carapils. Wheat is great, too. I happen to use 5% 6-Row in lighter beers. All of these have a common contribution to foamstand: small protein's.
Head retention is a balancing act of surface tension. The protiens have hydrophobic (repels water) and hydrophyllic (attaches to water) parts. These attract and move water from a place of high concentration to lower and allow it to stay there (a bubble). As surface tension collapses, the head falls and the bubbles become larger.
Hop isomers also are hydrophobic and move themselves to the head, and enhance head retention by working with the proteins to suspend water in the bubble surface.
This is just a thumbnail overview. The biggest thing is to eliminate foaming, wherever you can.