I'm trying to figure out how to redeclare a theme's function from within a plugin. The problem is that I'm getting a "Fatal error: Cannot redeclare" when trying to activate the plugin. But if I add the code to already activated plugin - everything is working as expected. Is there something obvious that I'm missing?
Here's a simplified example of the code I'm using:
// In my theme I use function_exists check
if ( ! function_exists( 'my_awesome_function' ) ) {
function my_awesome_function() {
return "theme";
}
}
// Now I want to override 'my_awesome_function' output in a plugin
function my_awesome_function() {
return "plugin";
}
EDIT:
In the given example I need my_awesome_function()
to return plugin
if the plugin is active and theme
otherwise. So I need to keep the original function in the theme.
Basically, I thought that if such approach works for child themes, it should work for plugins too. But obviously, I was wrong.