0

I have below code.

add_action( 'admin_init', [$this, 'settings_page_registration'] );

I would like to use enqueue_assets function name inside add_action().

Should I use like below ?

add_action( 'admin_init', [$this, 'settings_page_registration', 'enqueue_assets'] );
2
  • 1
    No, that's not how it works. What are you trying to do? Why do you need to pass the function name like that? May 10, 2022 at 3:39
  • Thanks @JacobPeattie. I would like to call the function at admin_init. Thanks.
    – Foysal
    May 10, 2022 at 3:53

1 Answer 1

2

If you need to call enqueue_assets at admin_init, then add a new add_action():

add_action( 'admin_init', [$this, 'settings_page_registration'] );
add_action( 'admin_init', [$this, 'enqueue_assets'] );

That said, if your assets are JS scripts or CSS, you should consider wp_enqueue_script() & wp_enqueue_scripts

1
  • 1
    This is the correct approach. One advantage of this method that I would like to point out is that, when each function is added separately, each function can later be removed independently by using remove_action, if ever needed.
    – AncientRo
    May 10, 2022 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.