Hey,
I want to avoid using the google analytics tracking code when using the admin.
I looked around the code and found that the function handling the tracking code is avia_get_tracking_code for building the code and avia_print_tracking_code for printing it.
I would like to modify my child theme so the printing of the code will only occur when using non logged in users but there is no way to replace only the printing (avia_print_tracking_code) – in order to do that I will need to override the avia_get_tracking_code (which I don’t want).
Is there a better way to do it or is that the only way?
Hey Zohar!
You could try this.
add_action( 'init', 'enfold_customization_remove_ga', 20 )
function enfold_customization_remove_ga() {
if ( is_user_logged_in() ) {
remove_action('wp_head', 'avia_print_tracking_code', 100000);
remove_action('wp_head', 'avia_print_tracking_code', 100000);
}
}
But overriding the function would work just as well.
Cheers!
Elliott
why is the remove action written twice? is that correct?
i think the second one should have been “wp_footer”.
Hi!
Yes, you’re correct. Replace the code with this:
add_action( 'init', 'enfold_customization_remove_ga', 20 )
function enfold_customization_remove_ga() {
if ( is_user_logged_in() ) {
remove_action('wp_head', 'avia_print_tracking_code', 100000);
remove_action('wp_footer', 'avia_print_tracking_code', 100000);
}
}
Cheers!
Ismael