Skip to content

Instantly share code, notes, and snippets.

@erropix
Created October 22, 2020 10:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erropix/617155dc0c27f25ea4800caa0638a2fd to your computer and use it in GitHub Desktop.
Save erropix/617155dc0c27f25ea4800caa0638a2fd to your computer and use it in GitHub Desktop.
Load CF7 assets in whitelisted pages only
/*
Title: Load CF7 assets in whitelisted pages only
Type: PHP > Custom Code
Location: Plugins loaded
Priority: 10
*/
// stop loading Contact form 7 JavaScript and CSS files
add_filter('wpcf7_load_js', '__return_false');
add_filter('wpcf7_load_css', '__return_false');
// selectively load Contact form 7 JavaScript and CSS files
add_action('wp_enqueue_scripts', function () {
$whitelisted_pages = array (
'home',
'contact-us',
);
if ( is_page($whitelisted_pages)) {
if (function_exists('wpcf7_enqueue_scripts')) {
wpcf7_enqueue_scripts();
}
if (function_exists('wpcf7_enqueue_styles')) {
wpcf7_enqueue_styles();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment