What is the right way to add a custom function?

Have you tried using a namespace?

If your function is in extras.php, then at the top of the file you’re trying to use your function in (ie the template file, type:

use Roots\Sage\Extras;

You would then write your function like:

Extras\word_limit($params);

Or if you want to use utils.php then change ‘Extras’ for ‘Utils’

4 Likes