In a plugin, I need to create a custom post type and the associated admin menu modifications with a class rather than procedural code. What is the basic skeleton that I need to build off of in order to do so, and how does that class get hooked into WordPress (i.e., how do I do the "add_action('init','register_my_custom_post_type'), etc. with a class)?

  • This very resource: wordpress.stackexchange.com/…
    – brasofilo
    Commented Oct 5, 2013 at 20:03
  • Just for fun I did a quick google search »wordpress oop«. I'm not going to post links here, but I can tell you, the first page alone is very resourceful. You might want to start there, besides looking deeper into what WPSE already offers - like brasofilo suggested. Another hint would be looking for those existing wordpress plugin boilerplates/skeletons. Commented Oct 6, 2013 at 11:35

1 Answer 1


(i.e., how do I do the add_action('init','register_my_custom_post_type'), etc. with a class)?

You pass the callback from inside the class, using $this:

add_action( 'init', array( $this, 'register_my_custom_post_type' ) );

Your Answer

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

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