I think you want to do something similar to what you did in delete_content.php
If I am correct there is a little difference between those 2 markups which is "&redirect_to=1" part in the link.

Plus there is still a repetition. You basically do the same computation twice in the same file. Correct me if Im wrong but L974, L1009 and LL1044 do the same thing over and over again.