WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer
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 '12 at 21:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.