最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp enqueue style - Move dashicons.min.css to Footer

programmeradmin0浏览0评论

Hey there WordPress community,

Google page speed is moaning about dashicons.min.css being on our site. However, we need it for the Mega menu.

I wanted to know if it's possible to move it to the footer.

I have tried this code already:

add_action( 'wp_print_styles', 'my_deregister_styles' );
function my_deregister_styles()    { 
   wp_deregister_style( 'dashicons' ); 
   wp_enqueue_style( 'dashicons', array(), false, true );
}

I have also tried a few other samples, however, nothing seems to work here.

Any ideas?

Thanks

Hey there WordPress community,

Google page speed is moaning about dashicons.min.css being on our site. However, we need it for the Mega menu.

I wanted to know if it's possible to move it to the footer.

I have tried this code already:

add_action( 'wp_print_styles', 'my_deregister_styles' );
function my_deregister_styles()    { 
   wp_deregister_style( 'dashicons' ); 
   wp_enqueue_style( 'dashicons', array(), false, true );
}

I have also tried a few other samples, however, nothing seems to work here.

Any ideas?

Thanks

Share Improve this question asked Jun 28, 2019 at 10:13 ChrisChris 234 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Please try below code :

add_action( 'wp_print_styles', 'my_deregister_styles' );
function my_deregister_styles()    { 
   wp_deregister_style( 'dashicons' ); 
}

Replace your css path "PATH_OF_CSS" :

add_action( 'wp_footer', 'register_wp_footer', 11 );
function register_wp_footer() { 
    wp_enqueue_style( 'dashicons', 'PATH_OF_CSS' ,array(), false, true );
}

Final working solution was:

add_action( 'wp_print_styles', 'my_deregister_styles' );
function my_deregister_styles()    { 
   wp_deregister_style( 'dashicons' ); 
}

add_action( 'wp_footer', 'register_wp_footer' );
function register_wp_footer() { 
    wp_enqueue_style( 'dashicons', '/wp-includes/css/dashicons.min.css');
}
发布评论

评论列表(0)

  1. 暂无评论