I want to be able to put a conditional PHP code in my theme which loads a different stylesheet when an admin or just one user (ID=1) is logged in.
Is there a WordPress function to achieve this?
There’s this div with a class (let’s say “example”) which is set to “display: none” on a post.
I just want admins to view it when they’re logged in and I’ll create a new CSS property for the class like:
.example {
display: block;
}
You can add a function for this in functions.php
I never used WP but if you can edit the code you could do a simple query if the admin is logged in and then use some inline-code
I would do three things:
1) Make sure you use the standard WordPress body_class function in your template. This will add lots of helpful classes to the body element of your HTML.
2) Add a filter on body_class to add a new helper class to the body when the user is an admin user. For example, in your theme’s
functions.php
:3) Use this new class in your standard CSS stylesheet to override your default when on an admin page:
This solution does things in a pretty standard, theme-friendly way, and avoids using either a separate stylesheet or an inline style.
You can write like as follows
you can check that the current user is admin by following way