I am not sure I understood the problem correctly. But in any case, you can use the Textinsert Plugin to create a macro that enters the namespace and the ID of a page in this page.
Using the HTML option of this plugin, you can also create an HMTL link that links the page to itself.
https://www.dokuwiki.org/plugin:textinsert
However, this method does not put the page ID in the source wiki code. (There is only the macro call included.) If you want to do that, you have to edit the *.txt file of the page at the server level in some way. The name of this file is the page name. The location of the file in the directory tree corresponds to the location of the page in the namespace structure. (In certain a sense, these are the "metadata" of the page you wrote about. In another form they are not available again.)
Feedback welcome - Michael Sy.