将wp_hook与插件一起使用

I am trying to add a style tag to each page using the wp_head hook. The code below shows what I have right now:

private function __construct() {

    add_action( 'wp_head', 'hook_anti_click_jack', 1 );

}

/* Prints out the style tag */
public function hook_anti_click_jack() {

    $output="<style id='antiClickjack'> body{display:none !important;} </style>";

    echo $output;

}

This does not print out the style tag. What could I be doing wrong? I am doing all this with a plugin I am making.

When your'e adding a hook in OOP way you've to pass the method through a reference to the class.

   private function __construct() {

   add_action( 'wp_head', array($this, 'hook_anti_click_jack'), 1 );

}

/* Prints out the style tag */

  public function hook_anti_click_jack() {

   $output="<style id='antiClickjack'> body{display:none !important;} </style>";

   echo $output;

}