Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
Wordpress how to apply css for specific roles using admin_head hook

I'm looking to add a line of code to apply css to certain roles.

For example:

If role "editor":

#wp-admin-bar-top-secondary{
    display:none;
}  

My snippet code:

add_action('admin_head', 'my_custom_style');

function my_custom_style(){
    echo '<style>
            
        /*remove media button*/
        .wp-media-buttons {
            display: none;
        }
        
        /*remove visual&code tabs*/
        .wp-editor-tabs {
            display: none;
        }
        
          </style>';
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You could use the roles property of the user object returned from wp_get_current_userDocs function.

add_action('admin_head', 'my_custom_style');

function my_custom_style()
{
    $roles = wp_get_current_user()->roles;

    if (!in_array('administrator', $roles)) 
    {
        ?>
        <style>
            /*remove media button*/
            .wp-media-buttons {
                display: none;
            }

            /*remove visual&code tabs*/
            .wp-editor-tabs {
                display: none;
            }
        </style>
    <?php
    };
}

Note:

  • Some users could possibly have more than one role, that's why I used in_array function!
  • Of course you could do the opposite by using the exclamation mark/'not operator'. (i.e !in_array())
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda