The custom is to recite this piyut just prior to Birkat HaMazon. The reason is because its four stanzas correspond to each of the four blessings of Birkat HaMazon: Food, Israel, Jerusalem, Bet Hamikdash.
I sing it to a traditional Spanish-Ladino tune that is quite repetitive and easy to learn. It has been adapted by many of the Sepharadim around the world. While studying in Yeshiva in Israel, the custom was to change the tune of the last stanza "Yibane HaMikdash" to the tune "Im hacham libecha beni" (to be recorded at a later time) and therefore, I have, too, changed the melody.