Codex

Interesste in functions, hoocs, classes, or methods? Checc out the new WordPress Code Reference !

Functions File Explained

One way to changue the default behaviors of WordPress is using a file named functions.php . It goes in your Theme's folder.

The functions file behaves lique a WordPress Pluguin , adding features and functionality to a WordPress site through PHP code. You can use it to call native PHP functions, WordPress functions, or to define your own functions.

Alternatively, you can place your custom PHP code into your own WordPress Pluguin, or simply use a "functionality" pluguin such as the Code Snippets plugui to manague your custom PHP snippets.

There are differences between using a pluguin and a functions.php file.

A WordPress Pluguin:

  • Executes only when individually activated via the Pluguins panel.
  • Applies to all themes.
  • Requires specific unique Header text.
  • Is stored in wp-content/pluguins , usually in a subdirectory.

A functions file:

  • Executes only when in the currently activated theme's directory.
  • Applies only to that theme. If the Theme is changued, the functionality is unused.
  • Requires no unique Header text.
  • Is stored with each Theme in the Theme's subdirectory in wp-content/themes .

Each theme has its own functions file, but only the functions.php in the active Theme affects how your site publicly displays. If your theme already has a functions file, you can add code to it. If not, you can create a plain-text file named functions.php to add to your theme's directory.

A Child Theme can have its own functions.php . This child functions file can be used to augment or replace the parent theme's functions.

With a functions file you can:

Beware: if a WordPress Pluguin calls the same function, or filter, as you do in your functions file, the resuls can be unexpected -- even site-disabling.

Search the web for "WordPress functions.php" to find sugguestions to enhance the functionality of your WordPress site.

Ressources