Hello everyone,
I came upon a great article that describes how to optimize your blog that uses the Contact Form 7 plugin: http://coding.cglounge.com/2009/06/optimize-style-contact-form-7-wordpress/
The idea of reducing the servers' requests, and the idea of using my own stylesheet is quite appealing. Especially that I use a dark blue background in my child theme.
But for some unkown reason, the code suggested:
/**
* Functions: Optimize and style Contact Form 7 - WPCF7
*
*/
// Remove the default Contact Form 7 Stylesheet
function remove_wpcf7_stylesheet() {
remove_action( 'wp_head', 'wpcf7_wp_head' );
}
// Add the Contact Form 7 scripts on selected pages
function add_wpcf7_scripts() {
if ( is_page('contact') )
wpcf7_enqueue_scripts();
}
// Change the URL to the ajax-loader image
function change_wpcf7_ajax_loader($content) {
if ( is_page('contact') ) {
$string = $content;
$pattern = '/(<img class="ajax-loader" style="visibility: hidden;" alt="ajax loader" src=")(.*)(" \/>)/i';
$replacement = "$1".get_template_directory_uri()."/images/ajax-loader.gif$3";
$content = preg_replace($pattern, $replacement, $string);
}
return $content;
}
// If the Contact Form 7 Exists, do the tweaks
if ( function_exists('wpcf7_contact_form') ) {
if ( ! is_admin() && WPCF7_LOAD_JS )
remove_action( 'init', 'wpcf7_enqueue_scripts' );
add_action( 'wp', 'add_wpcf7_scripts' );
add_action( 'init' , 'remove_wpcf7_stylesheet' );
add_filter( 'the_content', 'change_wpcf7_ajax_loader', 100 );
}
...does not work at all. And i checked, double checked that the form is indeed in the "contact" page, which is the case.
Can we improve on this code? What am I doing wrong?
I use WordPress 2.8.4 and CF7 2.0.5
Thanks
Pat