yes there is add this to your functions file should work 🙂
i check for the pages im loading in this condition only if its my front page i load the scripts n style, you can put your condition
[Code moderated as per the Forum Rules. Please use the pastebin]
yes, the tip Sina links to is very helpful
and i found an optimization
there’s another tip here but it does edit the core files
but, if we put the two lines in config.php
define(‘WPCF7_LOAD_JS’, false);
define(‘WPCF7_LOAD_CSS’, false);
and then before wp_head() we put:
if ( $_SERVER['REQUEST_URI'] == "/"
or $_SERVER['REQUEST_URI'] == "/contact/") {
if ( function_exists( ‘wpcf7_enqueue_scripts’ ) ) {
wpcf7_enqueue_scripts();
wpcf7_enqueue_styles();
}
}
this way, there’s no need to edit core files, or use custom pages, and depending on the theme, even custom headers…
the REQUEST_URI are the pages/posts with ContactForm7
and to check them out you can do:
echo "the url = " . $_SERVER['REQUEST_URI'];
@ brasofilo
Where exactly do I have to put this? You said “before wp_head()”. Does that mean before the wp_head() call in my theme’s header.php? I tried it, but couldn’t get it to work.
If I have only one page that uses the contact form, would this be correct?
<?php
if ( $_SERVER['REQUEST_URI'] == "/kontakt/") {
if ( function_exists( ‘wpcf7_enqueue_scripts’ ) ) {
wpcf7_enqueue_scripts();
wpcf7_enqueue_styles();
}
}
?>
@fotofashion
yes, in header.php
try this, just for checking the if’s are being accepted
<?php
if ( $_SERVER['REQUEST_URI'] == "/kontakt/") {
echo "this is kontakt page<br />";
if ( function_exists( ‘wpcf7_enqueue_scripts’ ) ) {
echo "function exists, enqueuing scripts<br />";
wpcf7_enqueue_scripts();
wpcf7_enqueue_styles();
}
}
?>
you’ll have to check the html source to see the echo’s
@ brasofilo
Ah, works like a charm now. Thanks a lot! The echo’s helped to locate the problem. I had to replace the backticks with straight ticks, like this:
<?php
if ( $_SERVER['REQUEST_URI'] == "/kontakt/") {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
wpcf7_enqueue_scripts();
wpcf7_enqueue_styles();
}
}
?>
i hate those microscopic errors
🙂
Not sure if it helps anyone, but instead of a particular page URL, I’m allowing the JS/CSS to be loaded based on a CUSTOM VARIABLE in the admin front-end – so no coding changes as my site scales ….
In my config.php I have the two lines:
define('WPCF7_LOAD_JS', false);
define('WPCF7_LOAD_CSS', false);
In my page.php (or suitable PHP files you need in your theme), first line is:
<?php if (get_post_meta($wp_query->post->ID, 'wpcf7',true)) { if ( function_exists( 'wpcf7_enqueue_scripts' ) ) { wpcf7_enqueue_scripts(); wpcf7_enqueue_styles(); } } ?>
I actually use this technique for quite a few plugins that load across an entire site but you want per-page loading.
Hope that helps someone out there!
@marky_uk
cool, an elegant solution
thx