A wellerism, so called after the character of Sam Weller and his father Tony in Charles Dickens' Pickwick Papers (1836-7), is an expression involving a familiar proverb, quotation, or cliche and its facetious follow-up. It's usually made of three parts: statement, speaker, and situation. An example commonly seen in definitions is: '"Everyone to his own liking," the old woman said when she kissed her cow.'
This kind of phrasing/joke has been around for millennia, even found in the work of Theocritus (3rd century B. C.), but it wasn't until the popularity of Dickens' characters who spoke this way that a name was coined in English for it. The Wellers' appearance in the novel and the theatrical adaptations of it, making such remarks as ' "Werry glad to see you, indeed, and hope our acquaintance may be a long 'un, as the gen'l'm'n said to the fi' pun' note.' led to a craze for such jokes at the time. And they've stayed around to some degree, to the point where in 1994 A Dictionary of Wellerisms, edited by Stewart A. Kingsbury and Wolfgang Mieder, was published; it attempted to collect all the wellerisms ever published in the English language.
(A subset of the wellerism is the Tom Swifty, where the situation is an adverb so that the expression runs like this: '"The doctor had to remove my left ventricle," said Tom half-heartedly.')