Custom admin stylesheet on Wordpress

I spoke before about having a custom stylesheet for the login page of wordpress. The same technique can be applied to all the admin section. The same way we did the login you just need to add a little function and a hook to add your special CSS:

function ysiv_head() {
        $path = get_settings(’siteurl’) . ‘/wp-content/plugins/ysivAdmin’;
        echo ‘<link rel="stylesheet" type="text/css" href="’ . $path . ‘/css/mainCss.css" />’."\n";
}

add_action(‘admin_head’, ‘ysiv_head’);

So first we declare a function called ysiv_head. In this function we declare a variable called $path and assigned it the value the ’siteurl’ variable plus the location of the CSS file on this site.

I have put mine in the plugin folder just because I am planning to make a plugin out of this instead of just a using the function.php file. We could do without the $path variable but I prefer to split long line of code, specialy urls.

Then we echo the stylesheet html tag with $path as the href value. And right after this function we create the hook which add a call to our function when wordpress loads the admin_head part. Fairly simple isn’t it?

Leave a Reply

Theme Forest ad
Wordpress Themes Collection ad
Woothemes

Poll

How do you start your WordPress plugins development projects?

View Results

Loading ... Loading ...