The Shulchan Aruch says that one shouldn’t kiss a child in shul. Does this apply to any form of affection or just kissing. Can a friend hug a friend when he greets him after a long period of time. Or should any affection be stopped in a mikdash me’at?
Rema writes (Orach Chaim 98), based on Binyamin Ze’ev (who quotes from Agudah), that a person should not kiss his children in shul, the reason being that one should instill in one’s heart that there is no love like the love of Hashem.
Therefore, the practice is mentioned specificially to children, to whom one feels unique love and affection. Yet, the custom is not to kiss at all in shul, both for the reason above and also because of mora shechinah, as mentioned by Orach Mishpat (Orach Chaim 22) and others.
Note, however, that poskim make a distinction between a kiss of love and a kiss of respect, such as kissing a rabbi’s or father’s hand, which is a prominent custom among Sephardim. See Ben Ish Chai, Vayikra 11; Ohr Le’Zion 2:45, sec. 55; Yecheveh Daas 4:12; KafHachaim 151:6. As poskim write, in our day it is customary to refrain from all kisses in shul, even those of ‘respect’.
Hugging is not generally discussed by authorities. Yet, it stands to reason (based on the rationale mentioned in poskim) that if the hug is meant as a show of love and affection (and not only respect), one should refrain from it in shul, leaving the shul before fully expressing one’s affection.