All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and messenger.
It is better to offer (voluntary) charity in secret as is the case with other voluntary acts of worship because this is far from showing off and ostentation. As for obligatory acts of worship, it is better to perform them in public as it does not usually imply showing off or ostentation. The Prophet, sallallaahu ‘alayhi wa sallam, said: “The best prayer of a person is that which he prays in his home, except for the compulsory prayers.” [Muslim]
‘Uqbah ibn ‘Aamer narrated that the Prophet, sallallaahu ‘alayhi wa sallam, said: “The person who recites the Quran in public is like he who gives charity in public and he who recites it in secret is like he who gives charity in secret.” [At-Tirmithi]
Moreover, Allaah, The Exalted, says (what means): {If you disclose your charitable expenditures, they are good; but if you conceal them and give them to the poor, it is better for you…} [Quran 2:271]
However, scholars said that if there are sharia-approved benefits in offering charity in public and the donor is shielded against showing off and ostentation, then it is better to offer it in public. Examples of this include being a role model in generosity and giving and encouraging others to mirror him and participate as well in various charitable activities.
Hence, the questioner should know that the basic principle in offering voluntary acts of worship is that they be offered in secret. Therefore, there is no harm in donating in the way the questioner had pointed out, as long as the intention was to motivate and urge people to offer charity. Also, the donor's intention should be pure and the act should be devoted to Allaah, the Exalted, solely, pure from any traces of showing off or ostentation. In this case, perhaps offering charity in public may be better than offering it in secret. If the questioner means advertising for the purpose of ostentation or Sum‘ah (i.e. seeking reputation or to be heard), then this is among the acts that render charities worthless. Allaah, the Exalted says (what means): {O you who have believed, do not invalidate your charities with reminders or injury as does one who spends his wealth [only] to be seen by the people ...} [Quran 2:264]
Allaah Knows best.