This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Dequeuing styles

  • Creator
    Topic
  • #26179
    cfunkyk
    Participant

    I’m having trouble dequeuing css. I’ve used a different carousel plugin than the one included and I’d like to disable its css, since it uses the same owl carousel and I don’t need it included twice. From searching the forum, it seems that dequeuing built-in stylesheets poses some challenges, so instead I have tried to dequeue the 3rd party stylesheet. In a perfect world I want to dequeue the themeblvd CSS with the handle ‘owl-carousel-css’, but will go with either.

    I’m using this, which does not have any effect. Is jumpstart doing something to override it?

    add_action('wp_print_styles', 'mytheme_dequeue_css_from_plugins', 100);
    function mytheme_dequeue_css_from_plugins()  {
    	wp_dequeue_style( "owl.carousel.style-css" ); 
    }

    Site is here: http://brewstation.staging.wpengine.com/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #26184
    Jason Bobich
    Keymaster

    Hi,

    There are several different ways to accomplish this.


    Option 1: Here’s one way you can do it with just one line in your functions.php, and using the framework:

    themeblvd_remove_stylesheet('owl_carousel');

    Option 2: Or, I’m assuming you also want to de-enqueue the JS file as, well. This can be done by filtering the framework’s global config.

    function my_global_config( $config ) {
        $config['assets']['owl_carousel'] = false;
        return $config;
    }
    add_filter('themeblvd_global_config', 'my_global_config');

    Now, the CSS and JS file won’t be included. — And chances are if you’re going to the extent to do this, there’s probably other assets you want to not include, as well. You can find where this filter is applied at /framework/includes/general.php and extend this method.

    function my_global_config( $config ) {
    
        $config['assets']['flexslider'] = false;
        $config['assets']['isotope'] = false;
        $config['assets']['owl_carousel'] = false;
        // etc...
    
        return $config;
    }
    add_filter('themeblvd_global_config', 'my_global_config');

    http://dev.themeblvd.com/tutorial/removing-framework-scripts/


    Option 3: And if you’re looking to do it in the more traditional way, you should (1) hook to wp_enqueue_scripts (wp_print_styles is deprecated and wp_enqueue_scripts hook is now meant to be used for all CSS and JS files), (2) use wp_deregister_style() and (3) make sure you’re using the correct handle.

    On the third point, if you see this printed in your site:

    <link rel='stylesheet' id='owl-carousel-css'  href='http://yoursite.com/wp-content/themes/jumpstart/framework/assets/plugins/owl-carousel/owl.carousel.min.css?ver=2.0.0-beta.2.4' type='text/css' media='all' />

    The registered handle with WordPress will be that HTML ID minus the “-css” at the end. So, that’s how you would know to do this:

    function my_dequeue_scripts() {
    	wp_deregister_style('owl-carousel');
    	wp_deregister_script('owl-carousel');
    }
    add_action('wp_enqueue_scripts', 'my_dequeue_scripts');
    #26185
    cfunkyk
    Participant

    Thanks – teaching us how to fish, not just giving us fish. 🙂

    #26186
    Jason Bobich
    Keymaster

    Yes, always!

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.