CSS and Javascript deregistration

Posted in: Newsmag
Post count: 69

Hi,
I use Contact Form 7 plugin in order to get the contact form (please see 43b.60a.myftpupload.com/contatti/). To avoid to get extra CSS and/or JavaScript file on every page of my site, I’ve followed this guide http://code.tutsplus.com/articles/optimizing-contact-form-7-for-better-performance–wp-31255. This way I should get the CSS and Javascript of Contact Form 7 plugin loaded only into the page where the form is really placed.
So that I’ve created a new functions.php file of my Newsmag-child theme which contains only the following code:

<?php
/*
GSM:file functions.php of the Newsmag-child theme
*/
if (!function_exists('aa_deregister_styles')) {
// Deregister Contact Form 7 styles
add_action( 'wp_print_styles', 'aa_deregister_styles', 100 );
function aa_deregister_styles() {
if ( ! is_page( 'contatti' ) ) {
wp_deregister_style( 'contact-form-7' );
}
}
}

if (!function_exists('aa_deregister_javascript')) {
// Deregister Contact Form 7 JavaScript files on all pages without a form
add_action( 'wp_print_scripts', 'aa_deregister_javascript', 100 );
function aa_deregister_javascript() {
if ( ! is_page( 'contatti' ) ) {
wp_deregister_script( 'contact-form-7' );
}
}
}
?>

But, after this I got the following error:

Warning: Cannot modify header information – headers already sent by (output started at /home/content/p3pnexwpnas10_data03/26/2630926/html/wp-content/themes/Newsmag-child/functions.php:26) in /home/content/p3pnexwpnas10_data03/26/2630926/html/wp-includes/pluggable.php on line 1207

What I’m doing wrong?
Thanks
Giuseppe

Post count: 6535

Hi

I’ve test this code on my side an works fine: http://screencast.com/t/DspIZkQ2Yat4 Please check the code from line 26 in Newsmag-child/functions.php because seams to be a conflict there. Also try to deactivate the child theme and add the code in functions.php file from main theme, then check again.

Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newsmag’ is closed to new topics and replies.