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).
<?php
/**
* Enqueue WPForms styles in homepage <head>
* @author Bill Erickson
* @see https://www.billerickson.net/code/enqueue-wpforms-style-head/
*/
function ea_home_wpforms_styles() {
if( is_home() && function_exists( 'wpforms' ) ) {
wpforms()->frontend->assets_css();
}
}
add_action( 'wp_enqueue_scripts', 'ea_home_wpforms_styles' );