Title: Page dependent ajax function
Last modified: August 30, 2016

---

# Page dependent ajax function

 *  [abdfahim](https://wordpress.org/support/users/abdfahim/)
 * (@abdfahim)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/page-dependent-ajax-function/)
 * 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.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * 0 replies
 * 1 participant
 * Last reply from: [abdfahim](https://wordpress.org/support/users/abdfahim/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/page-dependent-ajax-function/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
