Amina Inloes, Amina Inloes is originally from the US and has a PhD in Islamic Studies from the University of Exeter on Shi'a hadith. She is the program leader for the MA Islamic Studies program at the... Answered 1 year ago

Insofar as it is possible, it is good to try to adjust your environment to avoid triggers (for instance, avoiding online or television material with indecent content, looking away from certain advertisements or behaviour outside). I know that this can be difficult in some places which have become quite explicit! It is related from the Prophet (S) - and I am sure you have heard this - that if you lower your gaze, you will see wonders.

As for thoughts, to some degree we have control over our thoughts, you can try to change what you are thinking about and focus on something else if you find your thoughts wandering.

If you are a male and really struggling with this, fasting has been recommended too and may be helpful (as long as you do not do it to excess). 

Anyway this is part of being a normal human being, all you can do is your best and be compassionate with yourself while trying to navigate the straight path.