How to Enqueue Plugin Resources In the Head Section

By default, Frontend Publishing Pro adds all of its scripts and stylesheets at the end of the page. These resources are not added in the head section because it is very difficult for the plugin to anticipate whether the post or page about to get loaded has the shortcode in it. Some older versions of the plugin tried to add resources in the head section but it didn’t work properly on all websites, so we decided to go with the safer approach. Of course, the plugin could just add the scripts and stylesheets on all the pages of the site but that would be irresponsible as it would affect the performance of the whole website.

On most sites the effect of having the stylesheet in the footer is hardly noticeable. However if your website is different and you can see a slight delay then you should use the following snippet to get rid of this problem:

function wpfepp_enqueue_stylesheet_in_header()
{
	$form_pages = array(1, 2);
	if (class_exists('\WPFEPP\Constants\Assets') && (is_single($form_pages) || is_page($form_pages))) {
		wp_enqueue_style(\WPFEPP\Constants\Assets::FRONTEND_FORM_CSS);
		wp_enqueue_style(\WPFEPP\Constants\Assets::POST_LIST_STYLE);
	}
}

add_action('wp_enqueue_scripts', 'wpfepp_enqueue_stylesheet_in_header');

Don’t forget to add the IDs of your shortcode posts/pages in the $form_pages array. For instance if your form is present on a page with ID 32 and your post list is on a page with ID 233 then the array should look like this:

$form_pages = array(32, 233);