Most solutions I found are for front-end use. This is for a plugin, so the all activity is in the back-end.
How do I get the page ID that’s being currently use(edited) in the admin?
Note I’m out of the loop. I just need to get the ID of page(not posts) that I’m currently seeing in the back-end.
You can also use
Or you can use a hook (probably better).
You will need to add a conditional since this will run on all admin pages, I recommend using
get_current_screen();
For example to run only on pages:
You can add this code in functions.php file and it will give you a meta box above the publish settings box when editing a post or page.
This is probably the “most secure” way of checking what the current post is on the post edit (and add) page in wp admin.
You just use this code in the functions.php file, It will give you a current edit page or post ID