Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use PHP’s function_exists() to check whether a function is defined. In a WordPress theme, wrap a declaration in that check only when conditional definition is intentional; for ordinary theme functions, a distinctive theme prefix or PHP namespace is the better first defense against naming collisions.
Check for a PHP function with function_exists()
function_exists() checks whether a named PHP function is currently defined. WordPress’s Theme Handbook demonstrates guarding a theme setup declaration this way:
if ( ! function_exists( 'acme_theme_setup' ) ) {
function acme_theme_setup() {
// Add theme setup code here.
}
}
add_action( 'after_setup_theme', 'acme_theme_setup' );
The guard controls whether PHP makes the declaration. The add_action() call separately registers the callback so WordPress runs it at the appropriate point. The Theme Handbook identifies after_setup_theme as the first hook available after the theme’s functions.php has loaded. See Theme Functions and Custom Functionality (functions.php).
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minutePrefer unique names over blanket guards
Give functions a distinctive project or theme prefix, such as acme_theme_, or use a PHP namespace when that fits the codebase. Unique identifiers address the collision at its source rather than relying on load order to decide which implementation wins. WordPress recommends unique function and class names in its Plugin Handbook best practices.
#1 Best Overall
A guard is useful when an existing implementation is deliberately allowed to provide the function. It is not a harmless wrapper to add around every declaration: if another implementation with the same name loads first, the guarded declaration is skipped, and later code may silently use that earlier implementation. WordPress cautions against wrapping every function or class in existence checks and reserves override-style checks for shared libraries.
Choose the approach that matches the code
| Approach | Use it when | Tradeoff |
|---|---|---|
| Prefix or namespace the function | The theme owns the implementation. | Reduces accidental name clashes at their source; this is the normal choice for theme-owned functions. |
Guard the declaration with function_exists() |
A shared or intentionally replaceable implementation may already have defined the function. | Prevents a duplicate declaration, but the earlier implementation keeps the name and may be selected instead. |
Account for WordPress theme load order
Only the active theme’s functions.php runs. When a child theme is active, WordPress loads its functions.php immediately before the parent theme’s file; theme functions load after plugin files. An implementation loaded earlier may therefore have defined a name before a later theme declaration is reached. A guard can avoid a duplicate declaration, but it does not make shared names a sound design.
Rank #2
- Used Book in Good Condition
WordPress describes functions.php as behaving similarly to a plugin, while recommending a plugin for functionality that should remain available regardless of the site’s design. Put presentation and theme setup code in the theme; move design-independent site functionality to a plugin when it must persist through a theme change. See Theme Functions and Custom Functionality (functions.php).
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchDo not confuse function checks with query or feature checks
Is a PHP function defined?
Use function_exists( 'some_function' ) when the question is whether that PHP function has been defined.
Is the current request a particular kind of page?
Conditional tags such as is_home() test WordPress query context, not whether a PHP function exists. The query has not run when functions.php loads, so query-dependent conditional tags belong in a template or in code deferred to an appropriate later hook. See the Conditional Tags guidance.
Does the active theme support a feature?
Use current_theme_supports() to test theme support. To load a file only when a feature is supported, WordPress documents require_if_theme_supports( $feature, $file ). These checks answer a feature-support question, not whether a PHP function is defined. See require_if_theme_supports().
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Recommended Free Tools

