The above hack is for categories only. For this we have now generic shortcode features. Generic shortcode now allows you to use it directly in category.php file and it will take the category id. So this hack is not needed now.
Regarding generic shortcode, you can check Topic #5 here https://www.masonrylayout.com/documentations/