WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


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.