In this article we will see the functions.php file, how it works and how you can use it.
WordPress is known for being very customizable and flexible using the plugins system. But many a times we want to add the functionality to the theme or we want to add few small changes for which we do not want to add a plugin.
In that case WordPress' function.php is used. In latest premium WordPress themes the functions.php works as the main engine driving features and flexibility of the theme without requiring any external plugins, beside it is popularly used for injecting small codes like google analytics, fonts API, custom scripts, site wide hooks and filters.
Functions.php resides in the root directory of the WordPress theme. you can use all the functions of WordPress inside it just like the plugins. But as its tied to the WordPress theme, If you change the theme your changes will be lost. WordPress development guide does not recommend to directly change the core/original files of the theme which may lead to dependency hell in case of update is required, to avoid such scenario we can use child themes.
Child themes act as the modifier theme of the original theme, here we can define any change or overload the default functionalities and theme settings without changing the original theme.
Here are five such cases where it can be used.
1)Adding Google analytics to WordPress blog
There are many ways to add google analytics to the WordPress blog, but most of the times it is unnecessory to use a plugin for that, we can use following code in functions.php file to add google analytics to the site:
<code>
</code>