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.
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');
Note that cForms is hooking into
wp_head
, and you’re attempting to hook intowp_enqueue_scripts
. Thewp_enqueue_scripts
hook is fired inside thewp_head
hook (at priority0
, IIRC).So, your stylesheet is being enqueued at
wp_head
, priority0
, and the cForms stylesheet is being enqueued atwp_head
, priority10
. 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 than10
), for your stylesheet.