Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除所有主题CSS&;来自wp_head Wordpress的JS,但不删除wp admin toollbar_Css_Wordpress_Head - Fatal编程技术网

删除所有主题CSS&;来自wp_head Wordpress的JS,但不删除wp admin toollbar

删除所有主题CSS&;来自wp_head Wordpress的JS,但不删除wp admin toollbar,css,wordpress,head,Css,Wordpress,Head,在模板中,wp_head()函数添加了一系列样式和脚本。 这会覆盖主题的其他CSS,从而产生问题 我尝试使用一个函数来删除CSS和js。它工作了,但也从WP管理工具栏中删除了CSS function clear_styles_and_scripts() { global $wp_scripts; global $wp_styles; foreach( $wp_scripts->queue as $handle ) : wp_dequeue_script(

在模板中,wp_head()函数添加了一系列样式和脚本。 这会覆盖主题的其他CSS,从而产生问题

我尝试使用一个函数来删除CSS和js。它工作了,但也从WP管理工具栏中删除了CSS

 function clear_styles_and_scripts() {
     global $wp_scripts;
     global $wp_styles;

foreach( $wp_scripts->queue as $handle ) :

    wp_dequeue_script( $handle );
    wp_deregister_script( $handle );

     endforeach;

foreach( $wp_styles ->queue as $handle ) :

    wp_dequeue_style( $handle );
    wp_deregister_style( $handle );

    endforeach;

 }
  add_action( 'wp_enqueue_scripts', 'clear_styles_and_scripts', 100 );

虽然我不建议将所有脚本和样式出列,但您可以检查文件句柄以忽略该特定文件的出列:

foreach( $wp_styles ->queue as $handle ) :

    // allows admin bar to be added
    if( 'admin-bar' === $handle ) continue;

    wp_dequeue_style( $handle );
    wp_deregister_style( $handle );

endforeach;
这起作用了

  function clear_styles_and_scripts() {
  global $wp_scripts;
  global $wp_styles;
  $styles_to_keep = array("wp-admin", "admin-bar", "dashicons", "open-sans");

  foreach( $wp_styles ->queue as $handle ) :
   if ( in_array($handle, $styles_to_keep) ) continue;
    wp_dequeue_style( $handle );
    wp_deregister_style( $handle );

    endforeach;

  }
   add_action( 'wp_enqueue_scripts', 'clear_styles_and_scripts', 100 );

把所有的脚本和样式都排出来是个坏主意。为什么不把不需要的文件排出来?