Let me tell you of something proven by experience. If parents reform their own moral condition before the birth of a child, the latter will be pious. The actions, attributes and states of the parents prior to birth of their children exercise a profound influence on the children.
The son of a buzrug was very evil. Someone enquired: “Why such an evil son was born to such a pious man?” The buzrug said: “One day I ate the food of a wealthy man. I was overwhelmed by a desire for sexual relations. I had relations with my wife, and this son was conceived. This son is the fruit of that Mushtabah (Doubtful) food I had consumed.” The condition of the parents at the time of conception, good or bad, has its effect on the child.
The first step for the piety of children, is the piety of the parents. They have to be pious.
The second step is that after birth, parents should not commit any reprehensible deed in front of even the infant. The child’s mind is very impressionable. The scenes enacted in front of the infant are indelibly impressed in the mind of the child. These images are retained in the mind of the child. In later life the child acts according to the scenes impressed in his/her mind. Therefore bear in mind that your actions done in front of the child will influence him.
The third step is to provide the child with Deeni education, and to prevent him from un-Islamic acts. Prevent him from bad company, and let him be in the company of the pious.