How to attain sincerity

Question
How can I attain sincerity so that my deeds are completely sincere?
Answer

Righteous deeds, which are done for the sake of Allaah, being accepted, sincerity is its prerequisite. Therefore, it is a must that such actions should done purely with sincerity for Allaah, Most Exalted, and following the instructions of His Prophet ﷺ. If deeds are not done with sincerity for Allaah then that is not accepted, even if the deed was done in a correct manner according to the instructions of the Prophet ﷺ. Therefore, it is compulsory upon every Muslim that he must strive earnestly to correct his intention and ensure that his deeds are done for Allaah alone and he should not look at his deeds before or after or during it that it is done for the sake of the creation. Rather, he should look to ensure that it is done for the Creator who has imposed this duty upon him. Ibn al-Qayyim (may Allaah show him mercy) In his book al-Fawaa’id says, ‘When you seek sincerity but you find greed, then firstly slaughter it with the knife of despair. Then if you find the desire to receive praise and recognition, forsake them like those who love this world over the Hereafter. If you are able to slaughter greed and forsaking the need for praise and recognition, then sincerity becomes easy for you. If you say, what would make slaughtering greed and the need for having praise and recognition easy? I will say, slaughtering greed is made easy by your certainty that whatever you seek is but, in the Hands, and treasures of Allaah which nobody possesses save Him. No one can give anything to the creation from this treasure except for Allaah. As for seeking praise and recognition, this becomes easy to remove when you know that praise and recognition and censorship is for none except Allaah alone). Ibn al-Qayyim strengthens his view by citing a hadeeth about the Bedouin who came to the Prophet ﷺ and said to him, ‘O Muhammad, indeed my praise (of others) is worthwhile and my censure is appropriate.’ So the Prophet ﷺ said: ‘That is for Allaah, the Mighty and Sublime’. (Al-Tirmidhee: 3227). 
It is with great regret that we are unaware of these matters and instead focus on the world and its outward manifestation and its inhabitants. Who from amongst us thinks about this hadeeth, ‘If he thinks of me I think of him, and if he remembers me in a gathering I think of him in a gathering better than that’ (Al-Bukhaary, 7405). Therefore, a person must strive to be constant in the remembrance of Allaah regardless of the fact that he is alone or in a gathering. If in a gathering, he should remind them of this and he shall get the reward of equal measure. This will mean that Allaah will remember him alone and Allaah will remember him in the gathering of angels which is better than the gathering he remembered Allaah in.
If it was said to some people that some influential people or people in high position or ministers or leaders mentioned you yesterday and praised you. You will see he cannot contain himself from joy and happiness. However, this is a person like him who cannot benefit or harm. He cannot benefit him except by that which Allah has decreed for him. Nor can he harm him with anything except that which Allah has decreed for him. A Muslim must be aware of this and must seek to make his intention pure. Many scholars have said that many students of Islamic studies suffer from having sincerity to Allaah. Many seek counsel saying, I cannot be sincere in my quest for seeking knowledge. I have many obligations in front of me, I seek the certificate, a job, establishing a family, my future and the like. So should I leave studying Islam because my intention is not pure, that is to say not purely seeking to please Allaah, instead it is to seek the aforementioned. 
To such a person it is said: Leaving studying Islamic studies is not a solution. Rather, the solution is to strive with yourself to make your deeds sincere for Allah, Most High, in regards to seeking knowledge and other affairs. If Allah, Glory be to him, knows the truth of your intention He will help you and give you the ability. Also a Muslim must endeavour to focus on the deeds of the heart, He must pay serious attention to this, because the heart is the centre of all deeds. If the heart is good then the entire body becomes good and if the heart is corrupt the entire body is corrupt, like the Prophet (peace be upon him) told us in an authentic hadith, ‘Behold in your body there is a piece of flesh if it becomes good then the entire body is good and if it becomes corrupt than the entire body is corrupt behold that is the heart’ (Al-Bukhaary, 52). Therefore, we must pay attention and take this seriously and strive to rectify our hearts with what the Messenger of Allah (peace be upon him) had prescribed as cures to the heart. We should benefit and seek help from the books of scholars who have written about this subject such as Ibn al-Qayyim and Ibn Rajab (may Allaah show them mercy). We should seek to make our hearts concordant to these and sever all paths which would lead to corruption. It is Satan who severs the path to good in this regard. Ibn al-Qayyim (may Allaah show him mercy) says in his book, The Sufficient Response to the one who Asked for the Cure which is called the cure and the medicine, he mentioned rectifying the heart is done by closing all windows which does not help in rectifying the heart, such as idle tittle tattle, looking around excessively, eating excessively, sleeping excessively and excessive socialisation. Hence, when a person speaks it should be to the point and of benefit and when he's looking it is for the sake of benefit and not something that Allah has made unlawful for him and will harm him. In like manner, eating should be done without being excessive and according to the limits prescribed by law in the hadith of dividing the stomach into 3 units (see: Al-Tirmidhee, 2380). A person should seek Allaah’s help So that it's done for the obedience of Allaah. In like manner, should be done to the extent that it benefits people and it benefits him and not something that will be harmful for him and harm to be returned upon him. The same applies to excessive talk which wastes time without any benefit. If a person is able to end these excessive things, then that will close the window of harmful things penetrating the heart. Indeed, he is able to do that by the will of Allaah. And with His help and bestowed ability he will be able to make his heart firm and upright up on the path to Allaah.