You Get What You Pet
Petting = affection = reinforcement
When your dog is in any given state of mind and you give affection, you are reinforcing that state of mind and telling them you like that and it’s okay.
When your dog is nervous and shaking, cowering between your legs, your natural instinct is to comfort them with pets and hugs and affection - while that is what makes sense naturally to us as humans to help soothe each other, that doesn’t translate the same way to your dog.
Petting them in that moment validates the way they’re acting and thinking, showing them it is correct and acceptable. Instead of coddling your dog in that moment, offer extra guidance and direction, coach them through the situation so they can learn how to navigate in a healthy appropriate way.
When you come home and walk through the door and your dog is excited and barking and jumping on you and you are so happy to see them that you start giving them attention, you’re reinforcing that behavior and telling them it’s acceptable.
That becomes unfair to the dog when you have a guest come over and they display that same behavior and you try to correct them for jumping on your guests because it’s rude - the expectation has to be clear that that is not an acceptable behavior - our dogs won’t be able to understand that it’s okay when they get excited and jump on you but it’s not okay for them to do that with anyone else.
Bottom line: only give affection when your dog is doing something you like or displaying a behavior you like - don’t give affection when your dog is in an unhealthy state of mind or displaying rude or inappropriate behaviors.