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());
  • Is that actually working? Try add_action('wp_footer', array('Sample', 'footer_content')); instead and make sure your class is available when you call add_action. – hampusn Sep 16 '12 at 13:26

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.