How to limit preprocess functions base on a theme? I'm working on a theme that using hook_preprocess_node and hook_preprocess_page and everything is working fine. However, whenever I go to any admin pages, it's throwing me some errors because the array changes. So what I'm trying to achieve is to add a condition only to run this preprocess function if using my theme.

How can I limit the preprocess function base on my theme?
You can check theme active with function:

&lt;?php

$active = \Drupal::theme()-&gt;getActiveTheme()-&gt;getName();


Get list all themes with:

&lt;?php

$themes = \Drupal::service('theme_handler')-&gt;listInfo()