Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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