Different pages often need different set of scripts and styles for them.
I use functions.php and construction like this to load scripts and styles:
function load_assets() {
wp_enqueue_style( 'styles', get_template_directory_uri() . '/css/styles.css');
wp_enqueue_script('main-js', get_template_directory_uri() . '/js/main.js');
}
add_action( 'wp_enqueue_scripts', 'load_assets' );
I know I can put some condition here like this:
is_page()
but is there a better way?
Suggestion:
Can wp_register_script() be used to target specific pages?
is_page
also accepts a title or slug. there's alsois_page_template
that lets you target php template files.