WordPress hook directly after body tag

后端 未结 9 960
野性不改
野性不改 2020-12-14 16:39

I\'m having problems finding the right hook to use for my plugin. I\'m trying to add a message to the top of each page by having my plugin add a function. What\'s the best h

9条回答
  •  孤街浪徒
    2020-12-14 16:53

    Changes, changes, changes. So it appears that since March 2019 (from WP 5.2) we have a little nicer way to do this.

    There is a new function wp_body_open(). To support it, your theme has to call this function right after opening tag:

    
      
    
        ..
        ..
    
        
    
      
      
    
        
    
        ..
        ..
    
        
    
      
    
    

    And then you can use it in the same way you use wp_head or wp_footer hooks to print anything just after .

提交回复
热议问题