Do not believe in anything simply because you have heard it. Do not believe in anything simply because it is spoken and rumored by many. Do not believe in anything simply because it is found written in your religious books. Do not believe in anything merely on the authority of your teachers and elders. Do not believe in traditions because they have been handed down for many generations. But after observation and analysis, when you find that anything agrees with reason and is conducive to the good and benefit of one and all, then accept it and live up to it.
This quote, which is frequently attributed to Buddha, is, in fact, a fake. There’s an interesting analysis here of the likely origin of the quote (short version is that someone likely rewrote or paraphrased a genuine quote in order to make Buddha appear more secular/rational).
(So much the worse for Buddha, in my opinion. The fake quote is much more in line with what I’d expect from someone genuinely enlightened as opposed to the genuine quote).