Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use admin_head filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
February 11, 2023
5 minutes read

admin_head filter

Fires in head section for all admin pages.

To use admin_head filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

We at WePlugins, always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.

In the below live example, we have defined a function modify_admin_head_defaults and we registered using add_filter. The first parameter admin_head is the name of the hook, the second parameter modify_admin_head_defaults is the name of the function which needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed in the registered function.

Sometimes, you have to remove a registered hook so you can use remove_filter to remove admin_head filter.

Parameters

  • No parameters

Live Example

Example 1: Adding CSS to Admin Head

Below is an example of how you can use this hook to add custom CSS to the admin head.

    function weplugins_dolly_css() {
        $x = is_rtl() ? 'left' : 'right';
        echo "
        <style type='text/css'>
        #dolly {
            float: $x;
            padding-$x: 15px;
            padding-top: 5px;
        }
        </style>
        ";
    }
    add_filter('admin_head', 'weplugins_dolly_css');
    

Example 2: Modifying Admin Head Defaults

In this example, we update the $add_trashed_suffix variable according to your website requirements.

    function weplugins_modify_admin_head_defaults() { 
        // Update the $add_trashed_suffix variable according to your website requirements.
        $add_trashed_suffix = 'custom_suffix';
        return $add_trashed_suffix; 
    }
    add_filter('admin_head', 'weplugins_modify_admin_head_defaults');
    

Example 3: Removing a Hook Callback

To remove a hook callback, use the example below. Make sure to provide the same callback function name, priority, and the number of arguments while removing the hook callback.

    remove_filter('admin_head', 'weplugins_modify_admin_head_defaults');
    

Access Premium WordPress Plugins

Contact Us

If you’re having any trouble using this hook, please contact our WordPress Development Team and we’d be happy to assist you.

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.