Title: enqueue in functions.php or reference custom.js?
Last modified: August 22, 2016

---

# enqueue in functions.php or reference custom.js?

 *  [trial3rror](https://wordpress.org/support/users/trial_error/)
 * (@trial_error)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/enqueue-in-functionsphp-or-reference-customjs/)
 * Hi,
    Serious php/js beginner here.
 * I run a child theme and have loaded some google fonts in functions.php thus, 
   and it works fine:
 *     ```
       //Enqueue Google Fonts.
       function custom_enqueue_google_font() {
   
       $query_args = array(
        'family' => 'Roboto:300,400,500,700'
        );
   
        wp_register_style( 'google-fonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null );
        wp_enqueue_style( 'google-fonts' );
   
       }
       add_action( 'wp_enqueue_scripts', 'custom_enqueue_google_font' );
       ```
   
 * Now I want to add some jquery, so I created a script and then enqueued it in 
   functions.php which afterwards looks like this:
 *     ```
       //Enqueue Google Fonts.
       function custom_enqueue_google_font() {
   
       $query_args = array(
        'family' => 'Roboto:300,400,500,700'
        );
   
        wp_register_style( 'google-fonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null );
        wp_enqueue_style( 'google-fonts' );
   
       }
       add_action( 'wp_enqueue_scripts', 'custom_enqueue_google_font' );
   
       // Enqueue js
       function load_custom_script() {
       $url =  get_stylesheet_directory_uri() . '/js/custom.js';
       wp_enqueue_script('load_custom_script', $url, array('jquery'), 20150329, true);
       }
       add_action('wp_enqueue_scripts', 'load_custom_script');
       ```
   
 * This raises a number of questions:
 * 1) I now have two add_action(‘wp_enqueue_scripts’), is that okay?
    2a) I got 
   the google fonts code snippet from a site explaining the proper way to include
   google fonts in wordpress, but now that I have a custom.js something tells me
   it would be more proper/best practice/elegant to move the google fonts inclusion
   function to my custom.js? Am I mistaken? 2b) Doing so would call for a completely
   different code, right?

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [11 years, 1 month ago](https://wordpress.org/support/topic/enqueue-in-functionsphp-or-reference-customjs/#post-5953498)
 * > 2a)
 * The fonts are actually CSS files – how would you get them into your JS file?
 *  Thread Starter [trial3rror](https://wordpress.org/support/users/trial_error/)
 * (@trial_error)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/enqueue-in-functionsphp-or-reference-customjs/#post-5953499)
 * No idea (I admitted to being a beginner).
 * So my functions.php is alright as it is, then, with two instances of add_action?
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [11 years, 1 month ago](https://wordpress.org/support/topic/enqueue-in-functionsphp-or-reference-customjs/#post-5953512)
 * I think so. The Twenty Fifteen theme calls it twice for example [https://themes.svn.wordpress.org/twentyfifteen/1.0/functions.php](https://themes.svn.wordpress.org/twentyfifteen/1.0/functions.php)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘enqueue in functions.php or reference custom.js?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/enqueue-in-functionsphp-or-reference-customjs/#post-5953512)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
