Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jarrodmedrano/a70c512c55c026df19ea to your computer and use it in GitHub Desktop.
Save jarrodmedrano/a70c512c55c026df19ea to your computer and use it in GitHub Desktop.
Enqueue the css from Gravity Forms in WordPress.
// Gravity Forms style sheet
wp_register_style( 'gravity-forms', get_stylesheet_directory_uri() . '/library/css/gravity-forms.css', array(), '' );
// only load on contact page
if(is_page('contact')){
wp_enqueue_style('gravity-forms');
}
@mrwweb
Copy link

mrwweb commented Jun 13, 2023

A more universal solution is to enqueue the style with the gf_enqueue_scripts action:

add_action( 'gform_enqueue_scripts', __NAMESPACE__ . '\enqueue_gravity_forms_css' );
/**
 * Only load theme Gravity Form styles when there's a form on the page!
 */
function enqueue_gravity_forms_css() {
	wp_enqueue_style(
		'my-gravity-forms',
		get_theme_file_uri( 'library/css/gravity-forms.css' )
	);
}

In my tests, this outputs the styles after the main gravity forms ones, but you could add a higher WP priority to ensure the styles appear later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment