Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   Only run (non-theme related) javascript on pages it is needed (http://forum.bytesforall.com/showthread.php?t=14933)

kdawes01 Jul 23, 2011 05:41 PM

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

mimi Dec 19, 2011 10:20 PM

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.

kletskater Dec 19, 2011 11:18 PM

I have several pages where I have cf7 embeded.
Can I add those id's togeter in the code with separator(,)?

mimi Dec 19, 2011 11:27 PM

Quote:

Originally Posted by kletskater (Post 77681)
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 "!".

juggledad Dec 20, 2011 03:36 AM

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....

kletskater Dec 20, 2011 06:21 PM

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?

juggledad Dec 20, 2011 08:04 PM

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

kletskater Dec 20, 2011 08:18 PM

thanks juggledad,
not learned one day is a day not lived
the code mimi gave here works for me. The orriginal behinde the link, let my site crash.

juggledad Dec 20, 2011 08:31 PM

I'd personally put the code in the plugin, that's where I think it should be and atahualpa upgrades wouldn't effect it

kdawes01 Jul 13, 2012 10:40 AM

Hi Juggledad,
Thanks for the text widget thought... Comes under a "Doh!" to me!

Don't know if you are aware of the "Advanced Text Widget" plugin. It has a bunch of neat features such as being able to set what pages/posts it appears/doesn't appear, allows shortcodes & php, and can give a custom css style or ID. It can also give those traits to other plugins.

Coupled with Atahualpa's custom widget areas, it can be very powerful!

Thanks!
Ken


All times are GMT -6. The time now is 10:05 AM.

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