I have made a class file in my plugin folder.
Then I wrote,
class Sample{
function footer_content(){
echo "show any data";
}
}
Then I added the function footer_content to wordpress footer by using add_action command. But it didn’t show anything. maybe I am missing something in this, as it is not working.
add_action('wp_footer', Sample::footer_content());
1 Answer
Here’s reference from Codex
To use the add_action hook when your plugin or theme is built up using
classes, add $this to your add_action call together with the function
name within that class, like so:
class MyPluginClass {
public function __construct() {
//add your actions to the constructor!
add_action( 'save_post', array( $this, 'save_posts' ) );
}
public function save_posts() {
//do stuff here...
}
}