How to get an unique identifier for a page/post/category/tag etc.?

Everything in WP has an ID. As long as your theme is using body_class you probably already have built-in classes that will cover your scenario.

For example:

  • Pages will include a page-id-## class, where ## is the id specific to that particular page.
  • The homepage will include a home class and if it’s your main blog archive also a blog class.
  • Posts and custom post types will include a postid-## class, where ## is the id specific to that particular post/CPT.
  • Categories will include a category-## class, where ## is the id specific to that particular post.

So, you should be able to use built-in functionality to identify content. All your theme has to do is, in header.php, use body_class like this:

<body <?php body_class(); ?>>