Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

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

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


  #1  
Old Jul 23, 2011, 05:41 PM
kdawes01's Avatar
kdawes01
 
102 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
 
93 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
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
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....
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
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
 
93 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
 
23,765 posts · Mar 2009
OSX 10.11.5 WP 4.x Atahualpa(all) Safari, Firefox, Chrome
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
__________________
"Tell me and I forget, teach me and I may remember, involve me and I learn." - Benjamin Franklin
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 07:02 AM.


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