Created
October 22, 2020 10:24
-
-
Save erropix/617155dc0c27f25ea4800caa0638a2fd to your computer and use it in GitHub Desktop.
Load CF7 assets in whitelisted pages only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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