Site logo

Archived topic

Adding Javascript in External File

1 reply · Started by Cindy on January 14, 2018

Viewing posts 1–2 of 2

Hi. If I do not want to log in to my backend to edit the JS via GP Hooks (wp-footer), can I move the javascript to an external file?

You can, you'd just to install a child theme (https://docs.generatepress.com/article/using-child-theme/), and then use wp_enqueue_script() in your functions.php file:

function your_theme_js() {
    wp_enqueue_script( 'theme_js', get_stylesheet_directory_uri() . '/custom.js', array( 'jquery' ), '1.0', true );
}
add_action( 'wp_enqueue_scripts', 'your_theme_js' );

This assumes custom.js is in the root folder of your child theme.

This archived topic is closed to new replies.