Support

Account

Home Forums Backend Issues (wp-admin) Enqueue different stylesheets based off an option

Solved

Enqueue different stylesheets based off an option

  • I have a theme option setup under an ACF options page that I’d like to use to wp_enqueue_style different stylesheets as a result of that option.

    $theme = get_field('global_theme', 'option');
    
    function custom_scripts() {
        $stylesheet = ($theme == 'alt' ? '/styles/style.css' : '/styles/style-alt.css');
        wp_enqueue_style( 'custom-style', get_template_directory_uri() . $theme );
    }
    add_action( 'wp_enqueue_scripts', 'custom_scripts' );

    However, I can’t seem to access the option, it just returns empty.

    Am I able to access the option from the functions.php in this context?

    Cheers in advanced for any help anyone can provide 🙂

  • 
    function custom_scripts() {
        $theme = get_field('global_theme', 'option');
        $stylesheet = ($theme == 'alt' ? '/styles/style.css' : '/styles/style-alt.css');
        wp_enqueue_style( 'custom-style', get_template_directory_uri() . $theme );
    }
    add_action( 'wp_enqueue_scripts', 'custom_scripts' );
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Enqueue different stylesheets based off an option’ is closed to new replies.