m (Plurality typo) |
|||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{Languages| |
||
+ | {{en|Functions File Explained}} |
||
+ | {{ja|Functions File Explained}} |
||
+ | }} |
||
+ | |||
One way to change the default behaviors of WordPress is using a file named <tt>functions.php</tt>. It goes in your [[Using Themes|Theme's]] folder. |
One way to change the default behaviors of WordPress is using a file named <tt>functions.php</tt>. It goes in your [[Using Themes|Theme's]] folder. |
||
− | The functions file behaves like a [[Plugins|WordPress Plugin]], adding features and functionality to a WordPress site. You can use it to call |
+ | The functions file behaves like a [[Plugins|WordPress Plugin]], 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 Plugin, or simply use a "functionality" plugin such as the [https://wordpress.org/plugins/code-snippets/ Code Snippets] plugin to manage your custom PHP snippets. |
||
⚫ | |||
+ | |||
⚫ | |||
A WordPress Plugin: |
A WordPress Plugin: |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
* Applies to all themes. |
* Applies to all themes. |
||
⚫ | |||
− | * Should have a single purpose, e.g., convert posts to Pages, offer search engine optimization features, or help with backups. |
||
⚫ | |||
A functions file: |
A functions file: |
||
⚫ | |||
⚫ | |||
* Requires no unique Header text. |
* Requires no unique Header text. |
||
* Is stored with each Theme in the Theme's subdirectory in <tt>wp-content/themes</tt>. |
* Is stored with each Theme in the Theme's subdirectory in <tt>wp-content/themes</tt>. |
||
⚫ | |||
⚫ | |||
− | * Can have numerous blocks of code used for many different purposes. |
||
Each theme has its own functions file, but only the <tt>functions.php</tt> 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 <tt>functions.php</tt> to add to your theme's directory. |
Each theme has its own functions file, but only the <tt>functions.php</tt> 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 <tt>functions.php</tt> to add to your theme's directory. |
||
Line 37: | Line 42: | ||
== Resources == |
== Resources == |
||
+ | * [https://wordpress.org/plugins/code-snippets/ The Code Snippets functionality plugin] |
||
⚫ | |||
+ | * [https://css-tricks.com/wordpress-functionality-plugins/ WordPress functionality plugins explained] |
||
⚫ | |||
+ | * [https://www.smashingmagazine.com/2011/09/how-to-create-a-wordpress-plugin/ Creating a WordPress plugin] (in-depth guide, examples) |
||
+ | * Order of execution of Functions file: [http://wordpress.stackexchange.com/questions/26537/between-functions-php-widgets-and-plugins-which-is-loaded-first Between functions.php, widgets and plugins, which is loaded first?] |
||
Languages: English • File Explained 日本語 (Add your language)
One way to change the default behaviors of WordPress is using a file named functions.php. It goes in your Theme's folder.
The functions file behaves like a WordPress Plugin, 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 Plugin, or simply use a "functionality" plugin such as the Code Snippets plugin to manage your custom PHP snippets.
There are differences between using a plugin and a functions.php file.
A WordPress Plugin:
A functions file:
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 Plugin calls the same function, or filter, as you do in your functions file, the results can be unexpected -- even site-disabling.
Search the web for "WordPress functions.php" to find suggestions to enhance the functionality of your WordPress site.