I went through this but my son was a bit younger. I think you could try a reward system at his age. A star for each poo in the toilet and a big reward once he does 10 of them could work.
Try not to make a big deal about it if you can avoid it. If he's doing it for attention then any attention is a gain for him, even negative.

It might be worth getting it checked JIC it's a medical issue if if persists.