Add CSS To WordPress Admin, Add JS To WordPress Admin

Hi Friends, WordPress is very user-friendly CMS in which lots of things can achieved easily by adding plugins. But sometimes we need to add something in WordPress admin. For example in one project I added a plugin to add second title for pages called wp title 2. So when you add new page you can see 2 text box for 2 titles but that second new title box messed up with content editor, So to solve this issue I need to add CSS to WordPress Admin. You can use this same method to add JS to WordPress Admin too.

So here I am taking example to add css to WordPress admin. For example you want to add padding-top to  custom title div. So below is code to add CSS to WordPress admin :

<?php
function custom_padding()
{
?>
<style type="text/css">
.customtitlediv{
padding-top: 30px !important;
}
</style>
<?php
}
add_action('admin_head', 'custom_padding');
?>

Open functions.php file of your theme and add above code to it. In above code we have used WordPress action admin_head which call function ‘custom_padding’. It will call when admin load and print it in admin head, So by this way you can add CSS to WordPress admin.

I hope this will help someone. In same manner you can add JS code to admin of WordPress. Instead of css write down JS code or include js file by script tag.

No Comments

Leave a Reply