Use get_queried_object
to get information about the current page.
- if you’re on a single post, it will return the post object
- if you’re on a page, it will return the page object
- if you’re on an archive page, it will return the post type object
- if you’re on a category archive, it will return the category object
- if you’re on an author archive, it will return the author object
- etc.