Islam does encourage visiting graves since it reminds people of the hereafter. When visiting graves, a person is to make du`aa’(supplication) for dead parents and relatives and all Muslims and seek Allah’s forgiveness for them. It should be stressed that dutifulness to our parents extends beyond their death and continues as long as we live. Therefore, one should supplicate and do other acts that benefit the dead as much as possible for one’s parents after their death.

Sheikh AhmadKutty, a senior lecturer and Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states: This issue belongs to an area or realm which is beyond the confines of logic, reason, or experimentation. It belongs exclusively to the area of revelation. As far as we can know from the revelation, it is clear that those who are buried in the grave not only know their visitors, if they had known them prior to their death, but also return their greetings.
The Prophet (peace and blessings be upon him) has left us clear instructions to visit the graves of our relatives and friends, to greet them, and to offer prayers for them. This is lest we forget them after their death. Through frequent visits to their graves, we renew our relationship with them, invoke Allah’s mercy upon them, and remind ourselves of our final destination in the next world. It is clear upon pondering that such instructions have meaning only if the dead are able to know their visitors and are able to return their greetings.
Imam Ibn `Abd Al-Barr, in his famous work KitabAt-Tamhid, cited the following report on the authority of Ibn `Abbas: The Prophet (peace and blessings be upon him) said, “If a Muslim were to pass by the grave of his believing brother whom he used to know in this world and greet him, the latter would recognize him and would return the same” (Abu Dawud).
The Prophet (peace and blessings be upon him) further taught us to visit the graves of our relatives and friends and offer greetings, thus:

As-Salaamu `alaikumdiyaaraqawminmu’mineenwainna in shaaAllahbikumlahikunyaghfiru Allah lanaawalakumwalisaa’iri Al-Mulsimeen.
(Greetings of peace to you, O believers, dwelling in these residences; with Allah’s leave we will also be joining you in the near future; may Allah forgive us and you and all the Muslims.)
Furthermore, referring to the disbelievers who were slain in the Battle of Badr, the Prophet (peace and blessings be upon him) said, “Surely you are not better able to hear me than them; but the only difference is that they cannot respond to me”(Al-Bukhari and Ahmad).
to conclude, we should continue to visit the grave of our loved ones and greet them and offer prayers and supplications on their behalf. In sha‘ Allah, they will be able to know you when you visit them. May Allah grant us sound understanding of our religion and sincerity in practicing it. Ameen.