I am trying to call a custom function inside the constructor function. Which action hook to be used?

class myClass{

  public function __construct(){

        add_action('$hook', array($this, myFunction);

  public function myFunction(){
      echo "I am called";

Additionally, I have two questions

  1. What would be the intention of private construct instead of public?
  2. Which one is better to use; singleton class or the normal call.

Looking forward


  • When will this function you need make affect on your Wordpress setup will decide the hook. Like if there is a function which you are using for adding menu admin you can make use of admin_init there. So, please first explain what will this function do. – BlueSuiter Apr 30 '17 at 8:20
  • This function is to be executed in single.php for setting up breadcrumb. Thanks – jeff Apr 30 '17 at 9:15
  • I think there you will need an action_hook. You can use any one of them as per the priority. Please look into this link for choosing our appropriate hook. codex.wordpress.org/Plugin_API/Action_Reference – BlueSuiter Apr 30 '17 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.