doucheyi1347 2015-09-18 17:04
浏览 54
已采纳

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

  • 写回答

1条回答 默认 最新

  • download1214 2015-09-18 17:09
    关注

    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;
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile