I’m writing a basic wordpress widget for my theme. I need to call my function inside the function widget. My function is located just outside the widget For example:
function my_function( $arg ) {
...
}
function widget( $args, $instance ) {
my_function($arg);
}
and it will give me error
Fatal error: Call to undefined function my_function() in...
However if i place my_function inside the widget function, then it works. For example:
function widget( $args, $instance ) {
function my_function( $arg ) {
...
}
my_function($arg);
}
I want to know why this would not work if it is placed outside the widget function? Thanks.
I think you may be in a PHP class (plugin class) when you declare your functions.
So try to modify your code like this :
I think it might be better then!
Let me know!