On one page of my WordPress site i use a photo-gallery. For this i need a js-file. Now the js-file is loading on everypage but its just needed one this specific page with the page id 2. Now the problem is, that is_page(2) is not working in the functions.php because the page id is not set then. Is it still possible to do this via functions.php or would you just add the script in the footer.php?
function footer_scripts()
{
// If query if current Page is not wp-login-php or admin page
if ($GLOBALS['pagenow'] != 'wp-login.php' && !is_admin()) {
wp_register_script('photo-gallery', get_template_directory_uri() . '/js/back-layer-photo-gallery.js', array('jquery'), '1.3', true);
wp_enqueue_script('photo-gallery');
}
}
add_action('init', 'footer_scripts');