Drupal 8 FAQ: What is the correct custom theme file name (preprocess functions)?

Drupal 8 FAQ: What is the correct name for a custom drupal theme file? That is, if I want to create a preprocess_node or template_preprocess_node function, what is the name of the file that those custom Drupal 8 preprocess functions go in?

In Drupal 8 your preprocess functions go in a file in your custom theme directory that should be named to end with the .theme filename extension. So if you are creating a theme named “foo”, you should have a directory named themes/foo under your Drupal 8 installation directory, and this file will be named foo.theme.

Here’s another way to see that:


While I’m in the neighborhood, this post shows the format for a Drupal 8 .theme file and preprocess function.