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?
You must be logged in to post a comment.
The same way you would any other:
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:
Also keep in mind
foo
is a very generic function name, perhaps the “omgfoo” plugin also has afoo
function. So prefix/namespace your function to something uniqueYou will eventually want to use actions and filters, as they’re safer and better practice, you can continue to read up on that here
You donât. A Theme should not rely on a plugin except in a very controlled environment. Use actions and filters instead.
So in your theme you might use:
⦠or â¦
In your plugin you use
add_action()
andadd_filter()
to change or add new content. This way the theme will still work when the plugin has been deactivated and you donât have to usefunction_exists()
.Active plugins are loaded (as in technically – their files are included and processed by PHP during WordPress load) by the time theme templates run.
So your function should be available and can be called as any other function:
for example.