Advertisement
arie_cristianD

add bot crawler check before view counter ajax

Jul 7th, 2025
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.77 KB | None | 0 0
  1. add_action( 'init', 'remove_jnews_view_counter_hook', 20 );
  2.  
  3. function remove_jnews_view_counter_hook() {
  4.     if ( function_exists( 'JNews_View_Counter' ) && class_exists( '\JNEWS_VIEW_COUNTER\Frontend' ) ) {
  5.         if ( JNews_View_Counter()->crawler_detect->is_crawler() ) {
  6.             global $wp_filter;
  7.             if ( isset( $wp_filter['wp_head'] ) ) {
  8.                 foreach ( $wp_filter['wp_head']->callbacks as $priority => $callbacks ) {
  9.                     foreach ( $callbacks as $key => $callback ) {
  10.                         if ( is_array( $callback['function'] ) && $callback['function'][0] instanceof \JNEWS_VIEW_COUNTER\Frontend && $callback['function'][1] === 'register_view_counter' ) {
  11.                             remove_action( 'wp_head', array( $callback['function'][0], 'register_view_counter' ), $priority );
  12.                         }
  13.                     }
  14.                 }
  15.             }
  16.         }
  17.     }
  18. }
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement