I have a function in my theme functions.php file which returns a value:

function my_theme_function() {
    return "100";

Anywhere in my theme templates I can simply do this…

echo my_theme_function()

…and I see the number 100 on the page. That’s cool.

But in my plugin I would have expected to be able do also get access to this function by echoing my_theme_function() but instead I get a ‘call to undefined function’ error.

The strangest part is I’m certain this was working a couple of days ago, but I’ve not touched the code since. I suspect some WordPress shenanigans, but I don’t know why or how to get around this.

Read more here: Call function from main WordPress theme in a plugin


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: