Contact Form 7
Include css/scripts only on pages which have a Contact Form 7 form? (4 posts)

  1. Ov3rfly
    Posted 3 years ago #

    Is there a way to have the css/scripts only included on pages which have a Contact Form 7 form?


  2. Ov3rfly
    Posted 3 years ago #

  3. Ov3rfly
    Posted 3 years ago #

    Above mentioned page has some basic instructions about:

    Step 2: Load the files on pages which contain contact forms

    As this suggests the use of an own template file, here is a much easier way:

    1. Do "Step 1" of above instruction.

    2. Then instead of "Step 2", add this to your header.php before wp_head() call:

    if ( is_singular() && get_post_meta( $post->ID, 'contact-form-7', true ) != '' ) {
    	if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {

    3. In pages/posts which have Contact Form 7 content, these where you copied [contact-form-7 id="123" title="Whatever"] to, add a WordPress Custom Field with Name contact-form-7 and set the Value to any value you like, e.g. include.

    The css/scripts of Contact Form 7 will then be included only on pages/posts which have that custom field contact-form-7 set.

    @Plugin author: Feel free to add this possible solution to your instruction page.

  4. Ov3rfly
    Posted 3 years ago #

    Note: If you are using WordPress 3.4.2, you will also need to apply a hotfix as the Custom Field code seems to be broken in this version:


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.