In its default settings, Contact Form 7 loads its JavaScript and CSS stylesheet on every page. You might think it would be redundant or wasteful, and want to load them only on those pages that contain contact forms. I understand the feeling, but there is a technical difficulty for a plugin in knowing whether the page contains contact forms or not at the start of loading. However, I can show you a way to work around that.

默认的,Contact Form 7 在每个页面载入他的 javascript 和 CSS。你或许认为这是多余的,浪费,你想在有表单的页面才载入。我能理解这种感受,但是在插件里很难找到页面里是否有表单在载入的时候。但是,我可以告诉你一个办法解决。

Step 1: Stop loading the JavaScript and CSS stylesheet on all pages

第一步:在所有页面停止载入 javascript 和 CSS。

When the value of WPCF7_LOAD_JS is set to false (default: true), Contact Form 7 does not load the JavaScript. You can set the value of this constant in your wp-config.php like this:

当 WPCF7_LOAD_JS 的值设置为 false (默认:true),Contact Form 7 就不会加载 Javascript, 你可以在 wp-config.php 里设置这个静态变量:

define('WPCF7_LOAD_JS', false);

Likewise, you can control the loading of the CSS stylesheet with WPCF7_LOAD_CSS. Contact Form 7 does not load the CSS stylesheet when the value of WPCF7_LOAD_CSS is false (default: true). You can set it in the wp-config.php like this:

同样的,你可以用 WPCF7_LOAD_CSS 控制 CSS 的载入。当 WPCF7_LOAD_CSS 设置为 false (默认: true) 时,Contact Form 7就不会载入 CSS 样式表。你可以在 wp-config.php 里设置这个静态变量:

define('WPCF7_LOAD_CSS', false);

Now you have succeeded in stopping the loading of the JavaScript and CSS stylesheet, but, unfortunately, you’ve also killed them on pages that contain contact forms — so we really need to get them back on the right pages. So, the next step is what you’ll need to load the files on to the explicit pages in which you need them.

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

For example, let’s say you have a page named “Contact” and it is the only page that contains a contact form. And suppose that you have a template file for the “Contact” page named ‘contact.php’ in your theme folder. Now you will need to load Contact Form 7′s JavaScript and CSS stylesheet specifically on the “Contact” page.

To do this, you must edit the ‘contact.php’ template file and insert the following lines into it:

<?php
	if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
		wpcf7_enqueue_scripts();
		wpcf7_enqueue_styles();
	}
?>

Note that wpcf7_enqueue_scripts() and wpcf7_enqueue_styles() must be called before wp_head() is called.

3,744 thoughts on “在需要的时候加载Javascript 和 CSS (Contact form 7)

  1. weight loss

    Hey there I am so thrilled I found your site, I really found you by error, while I was browsing on Google for something else,
    Nonetheless I am here now and would just like to say kudos for a tremendous
    post and a all round entertaining blog (I also
    love the theme/design), I don’t have time to go through it
    all at the moment but I have book-marked it and also included your RSS feeds, so when I have time
    I will be back to read much more, Please do keep up
    the excellent job.

  2. pornxxxv.com

    katrina kaif sex, Online Live XXX Movies,Hot Porn,Bollywood Sex,Desi mms
    scandal,pakistan indonesian arab sex, bangla sex hot video,
    Indian Mallu Sex Videos, bangladeshi new sex videos, sex video,
    hot sex videos, Bangladeshi Indian Shrilankan Sex , Hindu Hindu Girl Sex
    Videos,Bangla Sex Video, Sonakshi and Salman Sex, Cartoon sex xxx,
    Doctor and Nurse SeXSavita bhabhi 3Gp , Mp4
    HD Sex Videos, Indian Bhabhi 3Gp, Mp4 HD Videos sunny leone sex, xxx,
    3Gp Mp4 HD Videos, Bhabi Sex with Friend Videos, Bhabi Sex with Devar Videos, Bhabi Sex with Uncle Videos,
    Aunty Sex With Uncle Videos, Aunty With Boyfriend Sex Videos, Aunty With Husband
    Sex Videos, Indian Suhagraat Sex Videos, Mallu Bhabhi Sex Videos,
    Bollywood Movies Sex Videos, 18 years Babe Sex Videos,
    Indian Bhabhi, aunty, Sister, Mother Rape Sex Videos, Girlfriend Sex Strory
    Kahani In Hindi English, Desi Chudai Sex, Videos, Anjali
    Bhabhi, Priya Bhabhi, Riya Bhabhi XxX Videos Free Download Savita bhabi animated sex movie,
    xxx mp4, jangal chudai, hd mp4 android sex video, mast moti gand, mast chudai, gand in saari, best xxx video,
    top fuck video, xxx mp4 downloude, saree sex videos,
    indian bus sex, rape in train, big boobs sex,
    adult mp3, indian actress sex, Desi Chudai Sex, Google Best Ranked Wap sextgem.com, Sex video direct download link
    , mast moti gand, mast chudai, gand in saari, best xxx video, top fuck video, xxx mp4 downloude,
    www xxx sex bhabhi, Girls Sex With Animals, Dog,Horse, XxX Porn Mp4 3Gp Videos,bangla sex hot video, Indian Mallu Sex Videos,
    bangladeshi new sex videos, sex video, hot sex, hot sex video,
    hot sex videos, Bangla Sex, Bangladeshi Pakistani Shrilankan Sex , Hindu Muslim Girl Sex Videos,Bangla Sex Video,Mom son sex, brother sister sex,katrina kaif sex, indian actress sex,desi mms 3gp mp4 download, bhabi Rape sex
    , hindi sex video, Indian Sex xxx ,Hot Porn Clips,Online
    Live XXX Movies,Hot Porn,Bollywood Sex,Desi mms scandal,pakistan Indonesian arab sex, Live Stream Best XXX Online Mobile Sex Wap Desi Sex,
    indian actress sex, Mms Sex, Porn Sex, Aunty Sex, Incest
    Sex, Sunny Leone Sex, Desi Chudai Sex,Savita Bhabi animated
    sex movie, xxx mp4, jangal chudai, hd mp4 android
    sex video, mast moti gand, mast chudai, gand
    in saari, best xxx video, top fuck video, xxx mp4 downlode, saree sex videos, indian bus
    sex, rape in train, big boobs sex, adult mp3, indian actress sex, Mms Sex,Porn Sex,
    Girls Sex With Animals,Dog,Horse,XxX Porn Mp4 3Gp Videos, Youtube, xnxx .
    com, tube8, xhamster, pornhub, Badwap, 420wap, Sex2050, Sex2050,
    Sex2050, Porn2050, Xvideos, Bhojpuri Sex,
    Sexwap Mobi Online Sex 3gp ,indian sex videos xxx, Desi Sex Video xxx, full free
    Sex download xxx, TamilSex xxx, Punjabisex xxx, mp4 3gp sex video xxx, Pakistan xxx videos xxx,
    asian, Actress sex videos xxx, hardcore, homemade, lesbiansex, teensex, virgin, pornVideo, adult Video,
    Indian Desi Sex Stories, Sex Chat tamil sex videos,
    sex pakistani xx 3gp.com, sex pakistani xx 3gp.com,
    All russian porn sites 3gp, indian sex video, xxx video, indian sex
    video, arabic fuck mobi, http://www.pakistani x vdo.com,
    sex video, xxx sex, free 3gp porn, desi mobi.in, Sex video,frre
    iphone sxe 3GB porn, poran video 3gp com, frre iphone sxe 3GB porn, Indian desi girl sax video,
    sex xxx, deshi sex .com, sex xxx, free sex video download, free indian desi bhabhi, babhe xxx dese 3gp video download,
    x.videos com.free, video sexy small xxx 3GP, downloads sex video download,
    Download Sex Videos, Indian xxx 3gp videos, mp4 sex videos,
    Sex movie 3gp, Indian, Aunty, Bhabi, Mom son, School girl, teacher
    student, sister sex,indian xxx sex videos, pakistani Desi Sex Video,
    bangladeshi full free Sex download, TamilSex, Punjabisex,
    mp4 3gp sex, Pakistani sex, asian, Actress, hardcore, homemade, lesbiansex, teensex, virgin, porn Video, adult Video, Indian Desi Sex Stories,Indian Sex Chat , Online Sex 3gp,indian sex videos xxx, Desi Sex Video xxx, full free
    Sex download xxx, TamilSex xxx, Punjabisex xxx, mp4 3gp sex video xxx,
    Pakistan xxx videos xxx, asian, Actress sex videos xxx, hardcore, homemade, lesbiansex, teensex, virgin, pornVideo, adult Video, Indian Desi Sex Stories, Sex Chatbhabi
    sex, animal sex, young girl rape, katrina kaif sex, indian actress sex,desi
    mms 3gp mp4 download, bhabi Rape sex , hindi sex video, Indian Sex xxx
    ,Hot Porn Clips,Online Live XXX Movies,Hot Porn,Bollywood Sex,Desi mms
    scandal,pakistan indonesian arab sex, Live
    Stream Best XXX Online Mobile Sex Wap Desi Sex, indian actress sex, Mms Sex, Porn Sex, Bhabi Sex, Aunty Sex, Incest Sex,
    Sunny Leone Sex, Desi Chudai Sex

  3. Joesph

    I know this web site offers quality depending content and extra
    data, is there any other web page which provides such information in quality?

  4. Antonio eres subnormal

    you are really a good webmaster. The web site loading velocity is
    incredible. It kind of feels that you’re doing any unique
    trick. Furthermore, The contents are masterpiece. you have performed a great job on this topic!

  5. studybay help

    Thanks on your marvelous posting! I truly enjoyed readin it, you’re a great author.I will make sure to bookmark your bloog and definitely will come
    bawck sometime soon. I want to encourage you too efinitely continue your grea posts,
    have a nice day!

  6. a car that goes well

    This is very interesting, You’re a very professional blogger.
    I’ve joined your rss feed and look ahead to looking for more of
    your magnificent post. Additionally, I have shared your site in my social networks

  7. bring

    Oh my goodness! Amazing article dude! Thank you so much, However I
    am having difficulties with your RSS. I
    don’t understand why I can’t join it. Is there anybody
    else getting the same RSS problems? Anybody who knows the answer can you kindly respond?
    Thanks!!

  8. cameltoesex.net

    katrina kaif sex, Online Live XXX Movies,Hot Porn,Bollywood Sex,Desi mms scandal,
    pakistan indonesian arab sex, bangla sex hot video, Indian Mallu Sex Videos, bangladeshi new sex videos, sex
    video, hot sex videos, Bangladeshi Indian Shrilankan Sex
    , Hindu Hindu Girl Sex Videos,Bangla Sex Video,
    Sonakshi and Salman Sex, Cartoon sex xxx, Doctor and Nurse SeXSavita bhabhi 3Gp , Mp4 HD
    Sex Videos, Indian Bhabhi 3Gp, Mp4 HD Videos sunny leone sex, xxx, 3Gp
    Mp4 HD Videos, Bhabi Sex with Friend Videos, Bhabi Sex
    with Devar Videos, Bhabi Sex with Uncle Videos, Aunty Sex With
    Uncle Videos, Aunty With Boyfriend Sex Videos,
    Aunty With Husband Sex Videos, Indian Suhagraat Sex Videos,
    Mallu Bhabhi Sex Videos, Bollywood Movies Sex Videos, 18 years Babe Sex Videos, Indian Bhabhi, aunty, Sister, Mother Rape Sex Videos, Girlfriend Sex Strory Kahani In Hindi English,
    Desi Chudai Sex, Videos, Anjali Bhabhi, Priya Bhabhi, Riya Bhabhi XxX Videos Free Download Savita bhabi animated sex movie, xxx mp4, jangal chudai,
    hd mp4 android sex video, mast moti gand, mast chudai, gand in saari, best
    xxx video, top fuck video, xxx mp4 downloude, saree sex videos, indian bus sex, rape in train, big boobs sex, adult mp3, indian actress
    sex, Desi Chudai Sex, Google Best Ranked Wap sextgem.com, Sex video direct download link , mast moti
    gand, mast chudai, gand in saari, best xxx video, top fuck video, xxx mp4
    downloude, www xxx sex bhabhi, Girls Sex With Animals, Dog,Horse, XxX Porn Mp4 3Gp Videos,bangla sex hot
    video, Indian Mallu Sex Videos, bangladeshi
    new sex videos, sex video, hot sex, hot sex video,
    hot sex videos, Bangla Sex, Bangladeshi Pakistani Shrilankan Sex , Hindu Muslim Girl Sex
    Videos,Bangla Sex Video,Mom son sex, brother sister sex,
    katrina kaif sex, indian actress sex,desi mms 3gp mp4 download, bhabi Rape sex ,
    hindi sex video, Indian Sex xxx ,Hot Porn Clips,Online Live
    XXX Movies,Hot Porn,Bollywood Sex,Desi mms scandal,pakistan Indonesian arab sex, Live Stream Best XXX Online Mobile
    Sex Wap Desi Sex, indian actress sex, Mms Sex, Porn Sex, Aunty Sex,
    Incest Sex, Sunny Leone Sex, Desi Chudai Sex,Savita Bhabi animated sex movie, xxx mp4, jangal chudai,
    hd mp4 android sex video, mast moti gand, mast chudai, gand in saari, best xxx video, top fuck video,
    xxx mp4 downlode, saree sex videos, indian bus sex, rape in train, big boobs sex, adult mp3, indian actress sex, Mms Sex,Porn Sex, Girls Sex
    With Animals,Dog,Horse,XxX Porn Mp4 3Gp Videos, Youtube, xnxx .
    com, tube8, xhamster, pornhub, Badwap, 420wap, Sex2050, Sex2050, Sex2050, Porn2050, Xvideos, Bhojpuri Sex, Sexwap Mobi Online Sex
    3gp ,indian sex videos xxx, Desi Sex Video xxx, full free Sex download xxx, TamilSex xxx, Punjabisex xxx, mp4 3gp sex video xxx, Pakistan xxx videos xxx, asian, Actress
    sex videos xxx, hardcore, homemade, lesbiansex,
    teensex, virgin, pornVideo, adult Video, Indian Desi Sex Stories,
    Sex Chat tamil sex videos, sex pakistani xx 3gp.com, sex pakistani
    xx 3gp.com, All russian porn sites 3gp, indian sex video, xxx video, indian sex video, arabic fuck mobi, http://www.pakistani x vdo.com, sex video,
    xxx sex, free 3gp porn, desi mobi.in, Sex video,frre iphone sxe 3GB porn,
    poran video 3gp com, frre iphone sxe 3GB porn, Indian desi girl sax video, sex xxx, deshi sex .com, sex xxx, free sex video download, free indian desi bhabhi, babhe xxx dese 3gp video
    download, x.videos com.free, video sexy small xxx 3GP, downloads sex video download, Download Sex Videos, Indian xxx 3gp videos, mp4 sex videos,
    Sex movie 3gp, Indian, Aunty, Bhabi, Mom son, School girl,
    teacher student, sister sex,indian xxx sex videos, pakistani Desi Sex Video, bangladeshi full free Sex download, TamilSex, Punjabisex, mp4 3gp sex, Pakistani sex, asian,
    Actress, hardcore, homemade, lesbiansex, teensex, virgin, porn Video,
    adult Video, Indian Desi Sex Stories,Indian Sex Chat , Online Sex
    3gp,indian sex videos xxx, Desi Sex Video xxx,
    full free Sex download xxx, TamilSex xxx, Punjabisex xxx, mp4 3gp sex video xxx, Pakistan xxx videos xxx, asian, Actress sex
    videos xxx, hardcore, homemade, lesbiansex, teensex,
    virgin, pornVideo, adult Video, Indian Desi Sex Stories, Sex Chatbhabi sex, animal sex, young girl rape, katrina kaif sex, indian actress sex,desi mms 3gp mp4 download, bhabi Rape
    sex , hindi sex video, Indian Sex xxx ,Hot Porn Clips,Online Live XXX Movies,Hot Porn,Bollywood Sex,Desi mms scandal,pakistan indonesian arab sex, Live Stream Best XXX Online Mobile Sex Wap Desi Sex, indian actress sex,
    Mms Sex, Porn Sex, Bhabi Sex, Aunty Sex, Incest Sex, Sunny Leone Sex, Desi Chudai Sex

  9. taobao agent

    Thanks for the good writeup. It in reality was a amusement account it.

    Look advanced to more delivered agreeable from you! By the way, how could
    we be in contact?

  10. cricketer r p singh biography

    Have you ever thought about adding a little bit more than just
    your articles? I mean, what you say is important and everything.
    However imagine if you added some great visuals or video
    clips to give your posts more, “pop”! Your content is excellent but with pics and clips,
    this site could certainly be one of the most beneficial in its
    field. Awesome blog!

  11. Check This Post

    Great blog here!Additionally your web site sso much up fast!
    What web host aree you using? Can I get your
    affiliate link for your host? I desire my site loaded up as fast as yours lol

  12. glutax

    Hi there! This post could not be written any better! Reading through this post reminds me of my old
    room mate! He always kept talking about this. I will forward this post to him.
    Pretty sure he will have a good read. Thanks for sharing!

  13. mobile phones

    Hey there would you mind stating which blog platform you’re working with?
    I’m looking to start my own blog in the near future but I’m having a difficult time choosing
    between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is
    because your design and style seems different then most blogs
    and I’m looking for something unique.
    P.S My apologies for being off-topic but I had to ask!

  14. business plan

    Thanks for another informative site. The place else may just I am
    getting that type of information written in such an ideal way?
    I’ve a challenge that I am simply now operating on, and I have been at
    the glance out for such info.

  15. Free Watch Jav

    I loved as much as you will receive carried
    out right here. The sketch is tasteful, your authored material stylish.
    nonetheless, you command get got an impatience over that you wish be delivering the following.
    unwell unquestionably come further formerly again since exactly the same nearly a lot often inside
    case you shield this hike.

  16. 2 drive 1

    Pretty component of content. I simply stumbled upon your website and in accession capital to claim that I acquire in fact loved account your blog
    posts. Anyway I will be subscribing to your feeds or even I achievement you access consistently quickly.

  17. also

    I pay a quick visit each day a few web pages and websites
    to read posts, but this blog provides feature based content.

  18. www.handihand.se

    Wow that was odd. I just wrote an extremely long comment but after I
    clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say fantastic blog!

  19. The Ballistic Pitching Blueprint PDF

    Hello there, just became aware of your blog through Google, and
    found that it’s truly informative. I am gonna watch out for brussels.
    I will appreciate if you continue this in future.
    Numerous people will be benefited from your writing.
    Cheers!

  20. epson printer not printing black

    It’s the best time to make some plans for the long run and it is time to be happy.
    I have read this post and if I may just I wish to suggest you few interesting
    issues or advice. Maybe you can write next articles relating
    to this article. I want to read more issues about it!

  21. century

    Having read this I thought it was rather enlightening.
    I appreciate you finding the time and energy to put
    this short article together. I once again find myself personally spending a significant amount of time both reading and commenting.
    But so what, it was still worth it!

  22. Bandar Judi

    You are so awesome! I do not believe I have read through something like that before.
    So good to find another person with unique thoughts on this subject matter.
    Seriously.. thank you for starting this up. This website is something
    that is required on the web, somsone with a little originality!

发表评论