How can I get the ID of the current post/page/category in a way that matches the ID I get from menus using
- For pages, including the Posts Page, it is the page ID
- For categories, it is the category ID
I have tried using
global $wp_query; echo $wp_query->post->ID;, but it gives the ID of a post for category pages and the Posts Page. (first or last displayed post, depending on whether it is before or after the loop)
I add the last modified date and ID to menu items as data attributes from this question and want to save the last visit date to localstorage, keyed with the ID from the menu so I can compare them.