The Buddha followed the following 4 guidelines and advocated others to do the same.
1. If you know something that is not helpful and is untrue, then do not say it
2. If you know something that might be helpful, but is untrue, do not say it
3. If you know something that is not helpful and is true, do not speak about it
4. If you know something that is helpful and is true, then find the right time to say it.
We must be careful about humor, since it may fall into the “empty speech” (samppapalapa) category, which is a dasa akusala.
See, “Right Speech – How to Avoid Accumulating Kamma“.