Using add_action():
Purpose:
Actions are used to allow developers to execute custom code at specific points in WordPress's execution process.
Usage:
Actions are typically used to perform tasks such as adding elements to a page, modifying data before it is displayed, sending emails, or performing any other custom operation.
They do not usually return values.
Adding filters to hooks
Purpose:
Filters are used to modify data before it is displayed or processed by WordPress or a plugin/theme.
Usage:
Filters are commonly used for tasks such as modifying content, altering query results, changing attribute values, or manipulating data structures.
They return modified values that can be further processed by WordPress or other plugins/themes.
Theme setup functions
Theme_setup” function is a common convention used to set up various theme features and configurations.
Loading and minifying scripts & styles
For Scripts: You can manually enqueue your scripts in your theme's functions.php file and use WordPress's built-in functions to set dependencies and attributes.
For Styles: Similarly, enqueue your stylesheets in the functions.php file and use WordPress's functions to add them properly.
Including other php files
The "require_once" or “include_once” functions are typically used to include files that contain important functions, classes, or configurations that are necessary for your theme to work correctly.
You can also use require or include without the _once suffix if you need to include a file multiple times.
Why you need to avoid php closing tags
When the functions.php file (or any PHP file) has whitespace following its closing ?> tag like this:
Many editor configurations will automatically add an extra line at the end of files. When you add a closing ?> tag at the end of the file, it can be easy to miss this extra whitespace, which may cause the “white screen of death” in some environments.
The easiest way to avoid this issue is to leave the closing ?> tag out altogether, which is perfectly valid PHP and standard practice.