I would like to have 2 different header files that I can use depending on which section of the website I am on. For example, display custom header#1 if not logged in, and display custom header#2 if logged in. I want to enqueue different scripts and styles on each of the header files using functions.php. The problem is that I need to call wp_head() on each of the header files, which means that they will load the same scripts and styles. Any suggestions?


Check whatever conditions you want to enqueue specific scripts on within your enqueue function.

function wpd_enqueue_scripts() {
    if( is_user_logged_in() ){
        wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/logged-in.js', array(), '1.0.0', true );
    } else {
        wp_enqueue_script( 'script-name', get_template_directory_uri() . '/js/not-logged-in.js', array(), '1.0.0', true );
add_action( 'wp_enqueue_scripts', 'wpd_enqueue_scripts' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.