• 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)
Viewing 3 replies - 1 through 3 (of 3 total)

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