Of course cultural traditions should be considered when giving a gift! The gift is given for the enjoyment of the person who is receiving it. Why on earth would you give something that you know someone of that culture wouldn't enjoy?
Of course, if you aren't in the culture, it can be hard to know what is appropriate. Some things are obvious: don't give a strongly Jewish family a leg of the finest pork from your butcher. Others are less well-known: don't give a Chinese person a clock (it sounds like "giving a funeral" in several Mandarin dialects). In general, if it's a gift that you're putting a fair amount of money and time into, then it's polite to be thoughtful and thus do a little research to actually take into account the likes, dislikes, wants, and customs of the recipient. But if it's just something small like a minor party favour, then not knowing that the gelatin in your small bag of marshmallows makes them inedible to Muslims is a less-serious slip up that I'm sure a lot of people would happily let slide.
On the other hand, if you receive something which is considered rude in your culture (e.g. at a Japanese wedding, if you don't give money, or if you give the wrong amount of money, it is a huge faux pas), then do the same you would for any other gift: thank them for the thought and effort (if it seems it was done out of ignorance and not thoughtlessness) and throw it out. Only if appropriate, take the time later to make the giver aware of the usual customs so that they don't embarrass themselves at other similar events. The article above is a good example of exactly how not to do this. I mean wow, talk about rude.