How To Remove All Actions For Wp_Head Or Wp_Footer For Specific Page

Here we learn about how to remove all actions for wp_head or wp_footer for a specific template page.

Custom code copied and paste into your child theme’s functions.php file.

Here is an example for checking for a particular page by slug ‘my-workshop’.

<?php
function myblog_unhook_wp_head_footer(){
  global $wp_filter;
  if( is_page( 'my-workshop' ) ) {
    foreach( $wp_filter['wp_head'] as $priority => $wp_head_hooks ) {
      if( is_array( $wp_head_hooks ) ){
        foreach ( $wp_head_hooks as $wp_head_hook ) {
          remove_action( 'wp_head', $wp_head_hook['function'], $priority );
        }
      }
    }
    foreach( $wp_filter['wp_footer'] as $priority => $wp_footer_hooks ) {
      if( is_array( $wp_footer_hooks ) ) {
        foreach ( $wp_footer_hooks as $wp_footer_hook ) {
          remove_action( 'wp_footer', $wp_footer_hook['function'], $priority );
        }
      }
    }
  }
}
add_action( 'wp', 'myblog_unhook_wp_head_footer' );
?>

Submit a Comment

Your email address will not be published.

Subscribe

Select Categories