Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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());
share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted

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...
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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