Answer: The Rema (OC 98:1) writes that fathers should not kiss their children in shul, as shul is a place where one should demonstrate their love to Hashem (Sefer Chassidim 255). R’ Avraham Yitzchak Kook (Orach Mishpat OC 22) writes that this prohibition applies to kissing other family members and friends, too.
The Ben Ish Chai (Vayikra 1:11) writes that while one should not kiss one’s young children in shul, the sefardi minhag of kissing the hand of a talmid chacham is commendable because it is done out of respect rather than personal affection. Likewise, one may kiss one’s father or Rabbi after being called up for an aliya where that is the accepted practice (See Kaf Hachaim OC 151:6; Ohr Letzion 2:45:55). R’ Ovadia Yosef (Yechave Daas 4:12) explains that showing them kavod is a form of honouring Hashem, just as one must stand for them, even in shul. However, one should not kiss any other relatives who one is not obligated to honour.
The Piskei Teshuvos (98:7) suggests that as this halacha is written in hilchos tefilla as opposed to hilchos bais hakenesses, this prohibition may only apply during davening. He quotes R’ Yisrael Avraham Alter Landau (Beis Yisrael OC 1:9) who notes that the Torah tells us that Moshe kissed Aharon on Har Sinai. He could only do so because the shechina was not present then.
Nonetheless, R’ Ovadia Yosef writes (Yabia Omer EH 3:10) that when making a chuppa in a shul, one must be careful not to embrace one’s relatives as kissing is always forbidden in shuls (See Rivevos Ephraim 2:66).
The Piskei Teshuvos (98:n69) writes that one would be allowed to kiss one’s child if they are crying, however, as this serves to calm them, rather than show affection.
In conclusion, one should not kiss one’s children in shul even after davening. One may do so to stop them crying if necessary.