I have created a function in my plugin myplugin
with the name foo
, how to call it from the frontend?
e.g. index.php?
I have created a function in my plugin myplugin
with the name foo
, how to call it from the frontend?
e.g. index.php?
The same way you would any other:
foo();
Active plugins are loaded before the theme files
You may want to check that your plugin is activated and the function is available so things dont go pear-shaped if you forget to activate it, like:
if(function_exists('foo')){
foo();
} else {
echo "oh dear you haven't activated/installed 'myplugin', go do that before the 'foo' feature is available";
}
Also keep in mind foo
is a very generic function name, perhaps the “omgfoo” plugin also has a foo
function. So prefix/namespace your function to something unique
You will eventually want to use actions and filters, as they’re safer and better practice, you can continue to read up on that here