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

How to use admin_print_footer_scripts-hook_suffix action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
January 7, 2023
5 minutes read

admin_print_footer_scripts-hook_suffix action

The dynamic portion of the hook name, $hook_suffix, refers to the global hook suffix of the current page.

To use admin_print_footer_scripts-hook_suffix action, first you have to register it using add_action. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.

At WePlugins, we 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 weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event and we registered it using add_action. The first parameter admin_print_footer_scripts-hook_suffix is the name of the hook. The second parameter weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event 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_action to remove admin_print_footer_scripts-hook_suffix action.

Parameters

  • No parameters

Live Example

do_action("admin_print_footer_scripts-{$hook_suffix}")

Below is an example of how you can use this hook.

Example 1: Adding a Script to Footer

This example demonstrates adding a custom script to the footer of the admin page.

    function weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event() {
        echo '<script>alert("This is a custom script added to the footer!");</script>';
    }
    add_action("admin_print_footer_scripts-hook_suffix", "weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event");
    

Example 2: Adding Custom Styles

Here, we add some custom CSS to the footer of the admin page.

    function weplugins_add_custom_styles_to_footer() {
        echo '<style> body { background-color: #f1f1f1; } </style>';
    }
    add_action("admin_print_footer_scripts-hook_suffix", "weplugins_add_custom_styles_to_footer");
    

Example 3: Removing a Footer Script

This example shows how to remove a previously added script from the footer.

    function weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event() {
        echo '<script>alert("This is a custom script added to the footer!");</script>';
    }
    add_action("admin_print_footer_scripts-hook_suffix", "weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event");

    // To remove the action
    remove_action("admin_print_footer_scripts-hook_suffix", "weplugins_execute_on_admin_print_footer_scripts_hook_suffix_event");
    

Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.

Access Premium WordPress Plugins

Contact Us

If you need any customization or are having trouble using this hook, please contact us. Our team at WePlugins would 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.