It’s not every day children are advised on how to raise their parents. Prince Harry came tantalisingly close this week. “You may find yourself frustrated with the older generation … But try to remove that judgment” he counselled. The kids should instead seize the chance to “help reshape mindsets” and empower the old fogeys to “think outside the box”.

One can only imagine what the Duke of Edinburgh will make of this, or how many middle-aged liberals will take kindly to being lectured by someone who once famously wore a Nazi costume to a fancy dress party. But while nobody likes to be caught on the sharp end of a sweeping and rather ageist generalisation, this week of all weeks it looks horribly as if the prince has a point.

Older people more likely to share fake news on Facebook, study finds Read more

Older people are more than twice as likely as the under-35s to regard Muslims as a threat to Britain’s success, and significantly more likely to hold the same view of immigrants generally, according to a report on rising racial tensions published this week by the charity Protection Approaches. They’re also far more likely to share fake news on Facebook: US research suggests the over-65s are four times as likely as younger people to spread such hoaxes.

But it’s not just pensioners that are the problem. Even the BBC was taken in this week by a nonsense of a story concerning Momo, a creepy-looking online character supposedly being used to incite teens to kill themselves, which on investigation turned out to be little more than a global rumour spread via parental anxiety. In all the moral panic about what teenagers get up to online, we arguably haven’t paid enough attention to what their parents are doing. And nowhere is that more obvious than in the outbreaks of antisemitism and Islamophobia currently infecting Britain’s two biggest political parties. Len Milner and Chris Smith, the two Conservative councillors from east Staffordshire who this week resigned after it emerged they had “liked” a Facebook cartoon about London’s mayor, Sadiq Khan, being beheaded, both look comfortably into middle age. So did Alan Bull, the prospective Labour council candidate suspended last year for sharing a Facebook post suggesting the Holocaust was a hoax.

We aren’t talking about hot-headed kids, or naive teenagers radicalised online. But nor are they old enough to have the excuse of growing up before civil rights movements existed. They are all young enough, and old enough, to know better. And the same is true of many of the councillors, candidates and even MPs in all parties caught similarly redhanded, not to mention the legions of voters behind them muttering that it all seems like a fuss over nothing.

Has something gone wrong with the sort of people attracted to public life? Or has something gone wrong with middle-aged people more broadly, and it’s just that before Facebook they didn’t get caught?

The inner workings of someone else’s mind will always be elusive, and motivations for posting can be complicated. But an individual’s social media history provides at least a rudimentary audit trail, a record of things that a generation ago would have been said in the pub and forgotten, and kids lectured from the cradle about online privacy increasingly seem to understand that better than their parents.

Is Facebook for old people? Over-55s flock in as the young leave Read more

It’s not just social media likes, comments and friendships that can be revealing but sometimes also the nature of what turns up on people’s feeds in the first place, since we see primarily what is shared by our friends. Nobody seems to be cracking jokes about Muslim politicians being beheaded, or sharing Rothschild conspiracies, in the few private Facebook groups I’ve joined. But that’s probably because they are respectively about dogs, cooking and parents of children in the same school class exchanging messages about lost PE kit. It is not an accident that some people encounter this stuff more than others.

Crude and patchy as it may be, the snapshot of people’s thinking provided by social media is confronting society with awkward truths. We all have no excuse for not seeing something that many voters of colour will have suspected forever, which is that all mainstream parties harbour a significant number of bigots and that government, central or local, risks being contaminated by that. There is now a moral imperative for parties to tackle racists in their ranks. The question is how far they’re prepared to make themselves unattractive to like-minded supporters in doing so.

The Tories have at least acted reasonably decisively in kicking recent offenders out. Not for them the drip, drip, drip of leaked emails suggesting that people close to their leader have meddled in decisions about expelling antisemites despite constant protestations to the contrary – or at least, not yet.

But Conservative high command is just as vulnerable as Labour to the criticism that they have normalised, condoned and even encouraged this stuff when they could have been showing moral leadership – or as Prince Harry put it, seeking to “reshape mindsets”. Where did Zac Goldsmith imagine the dog-whistle campaign crafted for the London mayoral elections was going to end up? What did Boris Johnson think he was doing, joking in his Daily Telegraph column about women wearing burqas looking like letter boxes?

Where were the concerted efforts to dispel stereotypes, over the years during which Sayeeda Warsi has repeatedly flagged up her party’s problem with Muslims and repeatedly been sidelined for it, or the equivalent of Momentum’s viral videos seeking to educate its members about antisemitic tropes?

For you cannot rely on the digital clumsiness of activists forever. Sooner or later, people will learn to cover their tracks better, but if their views haven’t fundamentally changed then the problem will not really have gone away. And that is where political parties, with all their expertise in crafting messages and changing hearts and minds, should be stepping up to the plate.

It’s true that the young and woke can occasionally get carried away by their own self-righteousness. And when a row blows up over a stray remark, journalists too could do better at distinguishing between ignorance and malevolence. Amber Rudd’s use of the words “coloured woman” when trying to say something supportive about racist abuse targeted at Diane Abbott was clankingly offensive. (Was she reaching for “woman of colour” and missed, or does she really talk like someone from the 1960s in private?)

But the mortified swiftness of her apology at least suggests willingness to learn, rather than outrage at the idea of having to. If we don’t want to be lectured by sanctimonious kids, royal or otherwise, then the onus has to be on the middle aged to do better in the first place.

• Gaby Hinsliff is a Guardian journalist