Where in my admin class should I place the action hooks for adding css, scripts and the add menu page?

In the __construct? Or should they be placed in a method?

1 Answer 1


Since you are using OOP, you probably want to architecture your plugin more efficiently. This is fine, but you'll be the one to structure your classes and build them.

So what if you put it in the __construct() function? That's fine, as long as you initiate a new instance of the class. Putting it in a method (private or public) will give the same thing as long as you call that method from inside or outside of your class.

I do use OOP for almost all of the WordPress plugins I create. Usually, I use the construct() function to add hooks for enqueue(ing) CSS, Scripts or other actions and filters. However, this is completely up to you, and you are free to design your classes as you wish.

  • Thanks a lot Abid! Actually I set up a simple MVC Pattern for all my plugins that I can use over and over again. I have a main controller which will take care of the frontend. The __construct of my maincontroller checks if there's an admin_init and if so, creates a new admin controller that extends my main controller.
    – user17235
    Jun 23, 2012 at 21:17

Your Answer

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