I was once told the best way to avoid loshen hara is to have a plan on how to properly approach the many different scenarios that you may encounter…. So the trick to avoid is to have a Strategy to combat loshen hara or a “game plan” so lets try to name some strategies to avoid loshen hara…
If s/t sounds unkosher say nicely that you are trying to be careful with what you hear and this sounds like s/t that might lead to lashon hara so lets talk about something else…( thats what I do and many times the person stops)
If you wouldnt want someone to say it about you there is probably something negative involved, therefore, dont say it about someone else and dont listen to someone else say it either.
I try saying, I would rather not listen nor speak loshon horah. That usually ends the conversation and moves on to another topic. Many of my friends do the same. Or you can say “I took it upon myself not to speak or listen to loshon horah, can we move on to another topic?”