How To Make Sure That My Action Hook Executes Last

How can I make sure that my_function action hook on ‘wp_head’ is executing last? One hack, that I’m using, is to give 999999 (a big number) as the third argument. But maybe some other hook on ‘wp_head’ is giving even bigger number than this one.

function my_function() {
    ?>
    <style>
        .custom-class{
                  background: blue;
        }
    </style>
    <?php   
}
add_action('wp_head', 'my_function', 999999);

Related posts

2 comments

  1. You define priority. It’s not a hack.
    Maybe it’s that you’re looking for is PHP_INT_MAX which is a PHP constant. So you can put it as priority number.

  2. If you want your CSS rule to apply, you must make it more specific. Of course if you add it the last one, it’ll work, but if other person adds the same on the same priority, it fails. The best approach is to make something like:

    body .custom-class

    Or make it more deep specific, adding more IDs or classes to your selector.

Comments are closed.