For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.
PHP Custom Function
PHP uses functions and loosely typed parameters. Function definitions can come before or after their usage so my preference when mixing PHP in with a mostly HTML page is to put the functions after the </html> tag.
The following is a complete example of adding PHP to an HTML page. You can put PHP functions at the top or bottom of your HTML page but my preference is for the bottom as demonstrated below.