Skip to content

Instantly share code, notes, and snippets.

@KeSch
Last active February 4, 2016 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KeSch/5be2394f61f6fd6e2272 to your computer and use it in GitHub Desktop.
Save KeSch/5be2394f61f6fd6e2272 to your computer and use it in GitHub Desktop.
Toolbox-Modul um das Laden von Contact Form 7 CSS und JavaScript Datein auf Seiten ohne Formular zu verhindern.
<?php
/*
Module Name: De-Register Contact Form 7 CSS & JavaScript
Module-URL: http://kevinschludermann.com/contact-form7/
Description: Contact Form 7 CSS und JavaScript Dateien nur auf Seiten mit Formular laden. [Frontend]
Author: Kevin Schludermann
Author URI: http://kevinschludermann.com
*/
/* Sicherheitsabfrage */
if ( !class_exists('Toolbox') ) {
die();
}
/* CF7 CSS-Files von Seiten ohne Formular entfernen */
function ks_deregister_styles() {
/* 'kontakt' muss durch die Titelform (URl-Slug) der Seite mit eingebundenem Formular ersetzt werden */
if ( ! is_page( 'kontakt' ) ) {
wp_deregister_style( 'contact-form-7' );
}
}
add_action( 'wp_print_styles', 'ks_deregister_styles', 100 );
/* CF7 JavaScript-Files von Seiten ohne Formular entfernen */
function ks_deregister_javascript() {
/* 'kontakt' muss durch die Titelform (URl-Slug) der Seite mit eingebundenem Formular ersetzt werden */
if ( ! is_page( 'kontakt' ) ) {
wp_deregister_script( 'contact-form-7' );
}
}
add_action( 'wp_print_scripts', 'ks_deregister_javascript', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment