Enqueue styles after a plugin

Is there a way to enqueue my style.css (and other stylesheets) AFTER a certain plugin enqueues its styles?

Specifically, I want my style.css to overwrite cforms’s styles, but when I change the priority of the add_action, it doesn’t do anything.

Read More

Here’s what I have:

    function rm_theme_styles()  
    {
            wp_register_style( 'rm_styles', get_template_directory_uri() . '/style.css', array(), null, 'all' );
            wp_register_style( 'jquery.fancybox', get_template_directory_uri() . '/js/libs/fancybox/jquery.fancybox-1.3.4.css', false, null, 'screen' );

            // enqueing:
            wp_enqueue_style( 'rm_styles' );
            wp_enqueue_style( 'jquery.fancybox' );
    }

    add_action('wp_enqueue_scripts', 'rm_theme_styles',10);

cforms:

    ### some css for positioning the form elements
    function cforms_style() {
        global $wp_query, $cforms_root, $localversion, $cformsSettings;

        ### add content actions and filters
        $page_obj = $wp_query->get_queried_object();

        $exclude  = ($cformsSettings['global']['cforms_inexclude']['ex']=='1');
        $onPages  = str_replace(' ','',stripslashes(htmlspecialchars( $cformsSettings['global']['cforms_inexclude']['ids'] )));
        $onPagesA = explode(',', $onPages);

        if( $onPages=='' || (in_array($page_obj->ID,$onPagesA) && !$exclude) || (!in_array($page_obj->ID,$onPagesA) && $exclude)){

            if( $cformsSettings['global']['cforms_no_css']<>'1' )
                    echo '<link rel="stylesheet" type="text/css" href="' . $cforms_root . '/styling/' . $cformsSettings['global']['cforms_css'] . '" />'."n";

                    ### add jQuery script & calendar
                    if( $cformsSettings['global']['cforms_datepicker']=='1' ){
                        wp_enqueue_script('jquery',false,false,false,false);
                        wp_enqueue_script('jquery-ui-core',false,false,false,false);
                        wp_enqueue_script('jquery-ui-datepicker',false,false,false,false);
                    }
                    echo '<script type="text/javascript" src="' . $cforms_root. '/js/cforms.js"></script>'."n";

            }
        }
    }

    add_filter('wp_head', 'cforms_style');

Related posts

Leave a Reply

1 comment

  1. Note that cForms is hooking into wp_head, and you’re attempting to hook into wp_enqueue_scripts. The wp_enqueue_scripts hook is fired inside the wp_head hook (at priority 0, IIRC).

    So, your stylesheet is being enqueued at wp_head, priority 0, and the cForms stylesheet is being enqueued at wp_head, priority 10. Since it outputs later, it is taking precedence over yours.

    The solution is to use the same wp_head hook, with a lower priority (i.e. a number higher than 10), for your stylesheet.