B.G 3.20
कर्मणैव हि संसिद्धिमास्थिता जनकादयः। लोकसङ्ग्रहमेवापि सम्पश्यन् कर्तुमर्हसि ॥२०॥
karmaṇaiva hi saṁsiddhimāsthitā janakādayaḥ। lōkasaṅgrahamēvāpi sampaśyan kartumarhasi ॥20॥
Indeed, King Janaka and others could attain perfection and be in that state by performing prescribed duties alone. You are only eligible to perform your duties, having an eye towards the welfare of the world.
Gīta Bhāshya 3.20
The knowledge of Brahman alone can give liberation. Performance of one's duties is a means to such knowledge. There are no other alternative means. 'karmaṇā' - while continuing to perform prescribed duties. Sentences that praise visiting holy places, etc. are meant to inspire ignorant towards right means, and do not directly result in liberation. King Janaka belongs to the category of Jnanins in the context of the Vedic scriptures.
Even the conduct practiced (by ancestors) is relevant, is indicated by 'karmaṇaiva' verse.
'karmaṇā' word's definitive meaning is 'while continuing to perform respective duties'. Knowledge is got only after performing the duties. Without it, there is no knowledge. They (king Janaka and others) are famous indeed as knowledgeable (jñānin) in the epic Mahabharata. "He alone is the wisest" - there are such Vedic testimonials as well. Even in Gīta verse 2.51 'budidhayuktaḥ', the enjoined duties are said as a means to knowledge. The Vedic testimonial "nānyaḥ panthāḥ" i.e. "there is no other means", rejects any other path. There is no opposition elsewhere to obtain liberation with the help of knowledge.
and, where visiting holy places is recommended as a means to liberation:
"Liberation can be attained either through the knowledge of Brahman or through death in Prayāga. Alternatively, by simply bathing in the river Gomati in the presence of Lord Krishna."
- such statements refer to freedom from results of accumulated sins. They are meant to praise such austerities. Indeed, even there, to an extent, such acts are advocated as a means to obtain the knowledge of Brahman. Without it, liberation is not possible.
"Without the knowledge of Brahman, liberation is not possible at any cost. Indeed, visiting holy places such as Prayag are suggested to gain knowledge, as a means to liberation."
- there are such statements as well. When statements that praise holy places are presented, they do not contradict the rule that knowledge (of Brahman) is a must (for liberation). It is similar to addressing an able servant with praise, saying:
"This one indeed is king. What you say, O King?"
-and such other statements.
Therefore, the Lord said:
"Such statements about pilgrimage places are eulogies to praise topics related to actions meant for the ignorant and deluded. The liberation happens by having the vision of mine alone, not otherwise."
-stated thus in Nāradīya Purana.
Hence, by the transcendental knowledge alone, liberation is possible. The prescribed duties are only the means to such knowledge.