Overwriting Volatyl Functions

Volatyl was designed with child theme development in mind. While there are certain parts of Volatyl that should never need editing in a child theme, there’s no reason to ignore easy-to-use functions that allow you to override certain Volatyl functionality in your child theme.

The way this works is by using PHP’s function_exists() function.

It simply checks to see if a function exists already or not. If it does, the function returns true. If it doesn’t, it returns false. We also know from PHP that ! means that something is nonexistent.

With that being said, many functions in Volatyl are wrapped in function_exists() conditionals like so:

// only run random_function() if it doesn't exist already
if (!function_exists('random_function')) {
	function random_function() {
		// development goodies
	}
}

Stay with me here.

Understand that a child theme’s functions.php file fires before a parent theme’s (Volatyl) does in WordPress. That’s true of any parent theme/child theme relationship. So when you’re building your child theme, any function that you create will run before the functions built into Volatyl.

Because of this firing order, you have the opportunity to run the same exact function names in your child theme as the ones found in Volatyl… as long as Volatyl has wrapped the function with function_exists().

Remembering that child theme functions.php fires before Volatyl’s, here’s a condensed version of what the server would read as it parses the PHP between both your child theme and Volatyl:

child theme function

// child theme override parent theme random_function()
function random_function() {
	// even better development goodies
}

Volatyl function

// only run random_function() if it doesn't exist already
if (!function_exists('random_function')) {
	function random_function() {
		// development goodies
	}
}

Take note that the first function above, located in your child theme, is not wrapped in function_exists(). It doesn’t need to be. The important part is that it uses the same exact function name as the one located in Volatyl.

With that in place, the second function above, located in Volatyl, now has to first go through the function_exists() conditional before it will run. In English, it says, “if random_function does not already exists, run it.”

As you’ve probably already figured out, random_function() does exists now that you’ve put it in your child theme.

Because the functions share the same name, your new function, edited however you want it, will now be used by Volatyl the same exact way the original function was. Sweet deal!

As you develop with Volatyl, you may find yourself sneaking around the framework files. That’s fine. If you find that the function you want to edit as ready to be overridden, go for it. If it’s not and you think it should be, please make a support thread instead of editing Volatyl files. Chances are the feature will be added immediately, if it makes sense to do so, and an update will be distributed.

Return to docs