Enqueue WPForms Style in Head

WPForms will always load styles when a form is displayed (unless you specifically tell it not to). But where the styles load can affect the look of your page. If WPForms waits until a form is displayed to load the styles, you’ll get the “flash of unstyled content” while the stylesheet loads.

WPForms is smart though. On single posts/pages, it checks to see if you included a form in the post content and, if so, loads the styles in the document’s head, before any of the content starts loading.

But there are some situations where this doesn’t apply, like your blog’s homepage and other dynamic archive pages, or if you’re loading the form using code. You can manually enqueue the styles if you know when you want them loaded.

The code below enqueues the WPForms styles on the blog homepage (home.php).

* Enqueue WPForms styles in homepage <head>
* @author Bill Erickson
* @see http://www.billerickson.net/code/enqueue-wpforms-style-head/
function ea_home_wpforms_styles() {
if( is_home() && function_exists( 'wpforms' ) ) {
add_action( 'wp_enqueue_scripts', 'ea_home_wpforms_styles' );
view raw functions.php hosted with ❤ by GitHub

form WPForms

Bill Erickson

Bill Erickson is a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk