Check content type of node in preprocess hook
To get the content type of a node, you just use $variables['node']-&gt;getType() or $variables['node']-&gt;bundle(). The first method just calls the second, so calling one or the other one doesn't make much difference. 

public function getType() {
  return $this-&gt;bundle();
}


The only difference is that bundle() is defined for every entity, since the concept of bundle is common for all the entities, while content type is the property Drupal used for nodes before changing them in one of the entities Drupal core modules implement; using bundle() makes easier to adapt the code for other entity types, but I don't think it is the case for the code you are using.