excep tonly one css, don’t load any css

I have below snippet but it doesn’t match what I want exactly.It avoids load any css file for my theme but also I want load stylepure.css. The stylepure css doesn’t contain unused css so I want to load only it for my homepage. How can I except the css file? thanks

   function pm_remove_all_styles() {
        global $wp_styles;
        $wp_styles->queue = array();
        wp_register_script('hekimscripts_input', get_template_directory_uri() . '/js/stylespure.css', array(), '2.7.1'); // input css
         wp_enqueue_script('hekimscripts_input'); // Enqueue it!
    }
    add_action('wp_print_styles', 'pm_remove_all_styles', 100);

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If this code works as excpected and you want to only limit it to front page you need to add a check for front page, like this

function pm_remove_all_styles() {
    if (!is_front_page()) return; // add this

    global $wp_styles;
    $wp_styles->queue = array();
    wp_register_script('hekimscripts_input', get_template_directory_uri() . '/js/stylespure.css', array(), '2.7.1'); // input css
     wp_enqueue_script('hekimscripts_input'); // Enqueue it!
}
add_action('wp_print_styles', 'pm_remove_all_styles', 100);


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x