• abdfahim

    (@abdfahim)


    Hi,

    I have different functions defined in functions.php which are required in different page. So, I was wondering should I use add_action() for all the functions directly or use if() condition to call based on page slug.

    For example, let say I have 10 functions defined in function.php which are called from 10 different pages. So, should I code like below (where I used if condition), or just add_action for all functions irrespective?

    Just from performance point of view.

    <?php
    function sendMail(){
       .....................
       .....................
        wp_send_json($myvar);
    }
    if(is_page('contac-us'){
        add_action('wp_ajax_mf_sendMail', 'sendMail');
        add_action('wp_ajax_nopriv_mf_sendMail', 'sendMail');
    }
    ?>
  • The topic ‘Page dependent ajax function’ is closed to new replies.