Wordpress Themes - WP Forum at BFA
Click Here To DONATE! Support the theme development, get more attention and additional benefits based on your donation level. Your forum name will be highlighted.

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme »

Only run (non-theme related) javascript on pages it is needed


Build custom WP THEMES, without
coding.
Click here for THEMEFRAME

From the author of Atahualpa, the #1 most
downloaded (700,000+) theme @ wordpress.org
  #1  
Old Jul 23, 2011, 05:41 PM
kdawes01's Avatar
kdawes01
 
90 posts · May 2009
Missoula, MT
Only run (non-theme related) javascript on pages it is needed

Hi,
I came across this Thesis-centric item about only adding the Contact Form 7 javascript on the pages it is actually needed...
http://andrewnorcross.com/tutorials/...in-for-thesis/

What would be the proper hook to use this in Atahualpa?

And it poses the thought more universally about other plugin javascript items and doing something similar and helping page loading....

Thoughts?

Ken
__________________
Ken | The Web Mechanic
Many thanks to Flynn for the amazing Atahualpa. Please consider a donation!

Last edited by juggledad; Dec 20, 2011 at 03:26 AM.
  #2  
Old Dec 19, 2011, 10:20 PM
mimi's Avatar
mimi
 
70 posts · Feb 2009
over there...
In case you are still looking for an answer, the following code should work.

Copy and paste it at the bottom of "functions.php" just before the "?>", and replace "200" with the page id or slug where C7 is enabled:

Code:
//unload C7
add_action( 'wp_print_scripts', 'deregister_cf7_javascript', 200 );
function deregister_cf7_javascript() {
    if ( !is_page(200) ) {
        wp_deregister_script( 'contact-form-7' );
    }
}
add_action( 'wp_print_styles', 'deregister_cf7_styles', 200 );
function deregister_cf7_styles() {
    if ( !is_page(200) ) {
        wp_deregister_style( 'contact-form-7' );
    }
}
Taken from here.
  #3  
Old Dec 19, 2011, 11:18 PM
kletskater's Avatar
kletskater
 
85 posts · Jun 2010
I have several pages where I have cf7 embeded.
Can I add those id's togeter in the code with separator(,)?
  #4  
Old Dec 19, 2011, 11:27 PM
mimi's Avatar
mimi
 
70 posts · Feb 2009
over there...
Quote:
Originally Posted by kletskater
I have several pages where I have cf7 embeded.
Can I add those id's togeter in the code with separator(,)?
Yes, check the link I provided, and read further down...
PS: make sure you read properly, I think you have to play with "!".

Last edited by mimi; Dec 19, 2011 at 11:34 PM.
  #5  
Old Dec 20, 2011, 03:36 AM
juggledad's Avatar
juggledad
 
21,982 posts · Mar 2009
OSX 10.8.5 WP 3.8.x Atahualpa 3.7.x Safari 6.x Firefox 25 XP
Be very careful giving out general advice without testing it

First: you can use the contact form 7 in a text widget - in this case you need it on ALL pages (unless you are using something like 'widget-logic'

Second: the code given will probably crash your site it you ever disable the plugin. It should be wrapped in a test for the plugins avaliability.

Third: if you are going to make changes to the theme code - remember to document it somewhere you will remember because the next time you update the theme, it will be gone. You might want to try adding t to the actual plugin code.

Seems to me the plugin author should give an option for the pages to load this....
__________________
If you like my help, please consider donating. I am happy to provide greater detail on this and other topics if you hire me. Please send detailed support requests to me as a private message, thank you.
Juggledad | Forum Moderator/Support

Last edited by juggledad; Dec 20, 2011 at 06:55 AM.
  #6  
Old Dec 20, 2011, 06:21 PM
kletskater's Avatar
kletskater
 
85 posts · Jun 2010
I think the code works/ i have no errors.
But how can I know the CF7 js an css files are not loaded on the pages, its not supposed to?
  #7  
Old Dec 20, 2011, 08:04 PM
juggledad's Avatar
juggledad
 
21,982 posts · Mar 2009
OSX 10.8.5 WP 3.8.x Atahualpa 3.7.x Safari 6.x Firefox 25 XP
You need to look at the source of the page. grab the page it loads on and the page it doesn't load on and compare the first 50 lines
__________________
If you like my help, please consider donating. I am happy to provide greater detail on this and other topics if you hire me. Please send detailed support requests to me as a private message, thank you.
Juggledad | Forum Moderator/Support

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic Backup of theme AND contents needed quintain Plugins & Atahualpa 6 Jul 5, 2011 03:12 AM
[SOLVED] problem with JavaScript in pages marek91 Center area post/pages 7 Nov 28, 2010 09:29 PM
category pages - with just the linked title, author, date of each related post janey73 Atahualpa 3 Wordpress theme 2 Jun 25, 2009 01:11 PM
Inserting Javascript on main page won't work but individual pages will everydayexplorer Atahualpa 3 Wordpress theme 2 Apr 11, 2009 10:31 PM


All times are GMT -6. The time now is 11:22 PM.


Powered by vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.