Hodge classes and the Jacquet-Langlands correspondence