• Pular para navegação primária
  • Skip to main content
  • Home
  • Sobre/About
  • Projetos
  • Fotografia
  • Blog
    • Feed/RSS
  • Boletim/Newsletter
    • Humanist Techology Newsletter
    • Boletín Tecnología Humanista
    • Boletim Tecnologia Humanista

Celso Bessa (sɛwsʊ bɛ:sa)

Prefiro construir pontes a muros

Você está em: Home / blog / tecnologia / WordPress: removing Customizer Custom CSS

WordPress: removing Customizer Custom CSS

18 setembro, 2017 por Celso Bessa

Quick tip for WordPress developers: how to remove custom CSS personalizado created by the Customizer. Pretty simple, actually.

[para a versão em português, clique aqui]

Let’s say we want page with ID 10 to not use the custom CSS, you just need to use the wp_head hook and remove wp_custom_css_cb function from wp_head actions queue. You would use something like this in your theme functions.php or in site specific plugin:

1
2
3
4
5
6
7
8
9
10
11
12
13
// first check if we are not in Admin area
if( !is_admin ){
 
    // get post global variable
    global $post;
 
    // check if post_id is equals to the post/page/custom_post ID we want to filter the CSS
    if( $post->post_id === 10){
 
        //remove wp_custom_css_cb from the actions queue on wp_head using the same priority, 101
        remove_action('wp_head', 'wp_custom_css_cb', 101);
    }
}

// first check if we are not in Admin area if( !is_admin ){ // get post global variable global $post; // check if post_id is equals to the post/page/custom_post ID we want to filter the CSS if( $post->post_id === 10){ //remove wp_custom_css_cb from the actions queue on wp_head using the same priority, 101 remove_action('wp_head', 'wp_custom_css_cb', 101); } }

Obviously, you can use other conditionals for removing the cusotm CSS. You could remove them from archives.

1
2
3
4
5
6
7
8
9
10
// first check if we are not in Admin area
if( !is_admin ){
 
    // check if we are in an archive
    if( is_archive() ){
 
        //remove wp_custom_css_cb from the actions queue on wp_head using the same priority, 101
        remove_action('wp_head', 'wp_custom_css_cb', 101);
    }
}

// first check if we are not in Admin area if( !is_admin ){ // check if we are in an archive if( is_archive() ){ //remove wp_custom_css_cb from the actions queue on wp_head using the same priority, 101 remove_action('wp_head', 'wp_custom_css_cb', 101); } }

Quick and simple. If you need, the gists are available on Github.

Arquivado em: tecnologia Marcados com as tags: CSS, Custom CSS, Customizer, PHP, tips, WordPress, WordPress Customizer

Sobre Celso Bessa

Prefiro construir pontes à muros. Cidadão, tecnologista de interesse público, consultor em cibersegurança, Media Democracy Fund fellowship alumni e fundador da Tecnologia Humanista.

Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (exceto fotografias com produto de terceiros ou pessoas)
Otimizado pela WoWPerations e hospedado na Digital Ocean
(Assinando Digital Ocean através deste link do programa indicação, você ganha crédito de 100 dólares para serem utilizados em até 60 dias, e eu ganho uma pequena comissão)