Where it comes from
In November 1964 Feynman gave Cornell’s Messenger Lectures, seven talks to “a packed audience” of students about how physical laws work, delivered “extempore from a few notes”. The BBC published them as a book, The Character of Physical Law (1965). The last lecture, “Seeking New Laws”, explains how a physicist finds a new law, and it opens with what may be the shortest description of the scientific method ever given.
“In general we look for a new law by the following process. First we guess it.” Then you work out what the guess implies and compare that with nature. “If it disagrees with experiment it is wrong. In that simple statement is the key to science.” And then, on page 156 of the MIT Press paperback, the famous line: “It does not make any difference how beautiful your guess is. It does not make any difference how smart you are, who made the guess, or what his name is — if it disagrees with experiment it is wrong.”
Guess, not theory
The popular version changes one word, and it’s a word worth keeping. Feynman’s point in this lecture is that new laws start as guesses. He wasn’t talking about grand finished theories being toppled. He meant that every idea, from the first moment, answers to experiment, however elegant it feels. The transcript of the spoken lecture that Wikiquote gives alongside the book version has “guess” too.
He also adds something the poster version leaves out. Right after the line he says that “one has to check a little to make sure that it is wrong”: the experiment may have been reported wrongly, there may have been “some dirt or something”, or the calculation may contain a mistake. Only after all that has been checked does a disagreement with experiment kill the idea. That’s not a loophole. It’s the same honesty pointed in the other direction.
Our take
Paraphrased, and a fair paraphrase. The meaning survives, and so do “beautiful” and “smart”. If you quote it, use his word, “guess”, and cite The Character of Physical Law, chapter 7. It’s a little humbler than “theory”, and humbler is the whole point.