Read the entire scene, starting with Ophelia and Laertes, and ending with Ophelia and Polonius. Then you can understand that Polonius only cares about appearances and advancing the interests of the Polonian family.
"To thine own self be true," also widely quoted, is really a wicked saying, and if followed would leave one with no standards of virtue at all, except naked self-interest.
Polonoius is really an evil dude, probably responsible for Hamlet's non-advancement to the Throne (Polonius was head of the Council), and thus behind the rottenness that Denmark is subject to.
And Polonius got his just desserts - "How now? A rat? Dead, for a ducat, dead!"
Thanks, I posted a shorter, less eloquent version of the same idea. Drives me crazy when half-read literature is misused.
The character of Polonius, and the hoary cliche status of his utterance notwithstanding, it’s still darn good advice and completely true.