How to determine if the current Drupal page is a contact page?
Have you tried

\Drupal::routeMatch()-&gt;getParameter('contact_form');


This returns an object of type ContactForm when the user is on a contact page. A simple detection you can do with getRouteName():

if ('entity.contact_form.canonical' === \Drupal::routeMatch()-&gt;getRouteName()) {
  // huhu, a contact form
}


You can have a look at ./core/modules/contact/contact.routing.yml. There are all routes available.