Strict Standards: Redefining already defined constructor for class bbdb in /home/themes/public_html/forums/bb-includes/db-mysql.php on line 12

Strict Standards: Declaration of BB_Walker_Blank::start_lvl() should be compatible with BB_Walker::start_lvl($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127

Strict Standards: Declaration of BB_Walker_Blank::end_lvl() should be compatible with BB_Walker::end_lvl($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127

Strict Standards: Declaration of BB_Walker_Blank::start_el() should be compatible with BB_Walker::start_el($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127

Strict Standards: Declaration of BB_Walker_Blank::end_el() should be compatible with BB_Walker::end_el($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127
Optimize Contact Form 7 Plugin [functions.php] « ThemeShaper Forums

ThemeShaper Forums » Thematic

Optimize Contact Form 7 Plugin [functions.php]

(2 posts)
  • Started 5 years ago by Baudesign
  • Latest reply from Baudesign
  • This topic is resolved
  1. Baudesign

    Hello everyone,

    I came upon a great article that describes how to optimize your blog that uses the Contact Form 7 plugin:

    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') )
    // 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



    Posted 5 years ago #
  2. Baudesign

    Ok, after pulling my hair for many hours, Here is the solution I found, thanks to Justin Tadlock

     * Functions:	Optimize Contact Form 7
    function deregister_cf7_js() {
       if ( !is_page('contact') ) {
    	wp_deregister_script( 'contact-form-7' );
    add_action( 'wp_print_scripts', 'deregister_cf7_js', 100 );
    function deregister_ct7_styles() {
    	wp_deregister_style( 'contact-form-7' );
    add_action( 'wp_print_styles', 'deregister_ct7_styles', 100 );

    It does most of what I was looking for.

    Now, I only need to figure out how to change the ajax-loader.gif icon to match my dark blue background.


    Posted 5 years ago #

RSS feed for this topic


You must log in to post.

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method GA_Filter::spool_analytics() should not be called statically in /home/themes/public_html/forums/bb-includes/wp-functions.php on line 586

Strict Standards: Non-static method GA_Filter::spool_this() should not be called statically in /home/themes/public_html/forums/my-plugins/googleanalytics.php on line 183