
When overriding a theme function in Drupal (or implementing a hook), you have to replace the first part of the function ( theme or hook) with the machine name of your theme or module that does this.
DRUPAL DEVEL THEME VARIABLES HOW TO
So let’s then not be afraid of php functions and see how to override theme_field() and make changes to a certain field. Themes General projects Gin Admin Theme Issues gintoolbar Add gintoolbarginisactive () check to all hook implementations Active Project: Gin Admin Theme Version: 8.x-3. However, keep in mind that on sites with many fields, this solution is not really recommended due to the performance impact.īecause it takes longer for the server to process template files than php functions, this can result in a slowdown of your website if you are using many fields.

So if you prefer overriding template files you can do this. The first one would affect the Body field of the Article content type, the second one would affect all fields attached to Article nodes, the third one would affect all the Body fields on the site and the fourth would affect all fields on the site. You have a few naming options to then target that template file to the field of your choosing: An alternative way of doing this is to copy to your theme the file from the core Field module and make changes in that. If you want to change the way these get displayed, you can override this function in your theme’s template.php file or module.

But I will also show you the other.ĭrupal uses theme_field() to display the values of fields in Drupal 7. Although there are a couple of ways of changing the default display of your fields, we will focus on the recommended one - using the theme_field() function of the Drupal API. In this article we are going to look at theming the output of specific fields in Drupal 7.
