WordPress hook directly after body tag

后端 未结 9 939
野性不改
野性不改 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:57

    I searched the internet for answers to the same question but found nothing. I figured out away to to work around it. My plugin infinite Ad Pay is based on this method.

    You need two hooks wp_head and wp_footer hook

     
    
    add_action( 'wp_head', 'my_buffer_holder_fxn');
    
    function my_buffer_holder_fxn(){
    ob_start()
    
    
    }
    
    
    function my_buffer_pour_out_fxn(){
    
    $get_me_buffers  = ob_get_clean();
    
    $pattern ='/<[bB][oO][dD][yY]\s[A-Za-z]{2,5}[A-Za-z0-9 "_=\-\.]+>|/';
    ob_start();
    if(preg_match($pattern, $get_me_buffers, $get_me_buffers_return)){
    
    
    $d_new_body_plus =$get_me_buffers_return[0]."
    This is below the body text or image or anything you want
    "; echo preg_replace($pattern, $d_new_body_plus, $get_me_buffers); } ob_flush(); } } add_action( 'wp_footer', 'my_buffer_pour_out_fxn'); // You can also use the method above to place anything in other sections of WordPress //No Javascript used

提交回复
热议问题