cforms II User Forum

Registration is currently disabled.
Guest

FAQs

Login form protected by Login LockDown.


Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

    

Wildcard usage:
*  matches any number of characters    %  matches exactly one character

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
How to Load CSS and Javascripts Conditionally
December 31, 2009
12:45 am
Guest

Please replace the ??? with your data!


I noticed that cForms (along with several other plug-ins) was loading scripts on every single page of my site even though I only actually use the form in one place. The scripts took about 20k, which isn't a lot, but I thought it would help reduce bloat to only load it on the page that needed it.

For anyone else that's interested in doing something like this, the code goes like this (and please correct me if you see that it could be better done):

// Load cForms javascript only on contact page function deregister_cforms() { if (!is_page('contact')) { remove_action('wp_head','cforms_style'); } } add_action( 'wp_print_scripts', 'deregister_cforms');

I also wrote a post optimizing your plug-in scripts for WordPress.

December 31, 2009
1:15 pm
Oliver
Munich, Germany
Admin
Forum Posts: 6400
Member Since:
March 6, 2005
Offline

Devin said:

Please replace the ??? with your data!


I noticed that cForms (along with several other plug-ins) was loading scripts on every single page of my site even though I only actually use the form in one place.

then you haven't configured cforms properly

The scripts took about 20k, which isn't a lot, but I thought it would help reduce bloat to only load it on the page that needed it.

For anyone else that's interested in doing something like this, the code goes like this (and please correct me if you see that it could be better done):

please note that when changing the core code you (a) quickly run the chance of breaking it and more importantly (b) if you do feel you need to change it, do it in accordance with the GPL requirements! (documenting your own code is a requirement)

however, better yet, configure cforms so it doesn't load the header on each page, it's two clicks. frown

January 1, 2010
11:58 pm
Guest

Hi Oliver.  I should have peered through the options a bit more.  I'll update my post.  Nice work and thanks again.

Forum Timezone: Europe/Berlin

Most Users Ever Online: 959

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

tracedef: 43

mores: 21

Gyrus: 20

frozenwaste: 18

asuffredini: 15

photoworks: 14

Member Stats:

Guest Posters: 3734

Members: 1463

Moderators: 3

Admins: 2

Forum Stats:

Groups: 1

Forums: 4

Topics: 5335

Posts: 18699

Newest Members: juredujmovic, dreamkeeper, rajattyagi, wrokaa, lukass

Moderators: Paul (421), cnymike (8), sonika (95)

Administrators: Oliver (6400), Nicky (3)