Community Forums › Forums › Archived Forums › Design Tips and Tricks › Only load Genesis Responsive Slider resources on pages that use them
- This topic has 7 replies, 2 voices, and was last updated 7 years, 2 months ago by Sridhar Katakam.
-
AuthorPosts
-
January 12, 2017 at 7:13 pm #199304joycegraceParticipant
Hi there,
I'm using Genesis responsive slider.I only need the slider to load on the home page.
Does anyone know of a copy/paste code snippet to be able to stop the plugin's resources (js & CSS) from loading on every page of a site it's installed on? Such as by naming IDs or page slugs for it to be loaded on?
I'm not much of a coder and also am not sure how to find the naming system to use by following instructions from other code snippets online that do this for other plugins.
For example, I use the code below in functions.php to remove Contact Form 7 scripts from pages not using them:
/** * Remove Contact Form 7 scripts + styles unless we're on the contact page * */ add_action( 'wp_enqueue_scripts', 'ac_remove_cf7_scripts' ); function ac_remove_cf7_scripts() { if ( !is_page('id-or-slug-goes-here') ) { wp_deregister_style( 'contact-form-7' ); wp_deregister_script( 'contact-form-7' ); } }
How can I achieve that with the Genesis responsive slider? I don't know what to replace "contact-form-7" with above. Or if the above would work...
Your help would be very much appreciated.
Find me at Joyce Grace (http://www.joycegrace.ca)
January 12, 2017 at 11:33 pm #199314Sridhar KatakamParticipantJanuary 13, 2017 at 12:16 am #199315joycegraceParticipantHi Sridhar, thank you so much for your help.
However, this does not seem to work for me. I also tried
is_home()
andif ( is_front_page() && is_home() )
from conditional tags instructions.When I view the source of a page that does not have the slider on it, I see this:
<style type="text/css">.slide-excerpt { width: 0%; } .slide-excerpt { bottom: 0; } .slide-excerpt { right: 0; } .flexslider { max-width: 1080px; max-height: 330px; } .slide-image { max-height: 330px; }</style>
And this
<script type='text/javascript'>jQuery(document).ready(function($) {$(".flexslider").flexslider({controlsContainer: "#genesis-responsive-slider",animation: "slide",directionNav: 1,controlNav: 0,animationDuration: 2000,slideshowSpeed: 8000 }); });</script>
I also tried an icognito window and cleared cache from using Autoptimize (and unchecked to optimize css and js in those plugin settings).
Am I doing something wrong?
E.g. view-source:http://www.executivesuite.ca/hot-desks-hourly-boardroom-vancouver/
Your code is currently in my functions.php file on the above site.
Same conversation happening here: https://wordpress.org/support/topic/only-load-genesis-responsive-slider-resources-on-pages-that-use-them/#post-8649561
Find me at Joyce Grace (http://www.joycegrace.ca)
January 13, 2017 at 12:22 am #199316Sridhar KatakamParticipantYou aren't doing anything wrong.
Those two blocks of code can not be removed w/ the code from my tutorial. You may want to post in the plugin's support forum for help in getting rid of those.
Adding the code from my tutorial does remove calls to plugin's style.css and the slider's js files.
January 13, 2017 at 6:12 am #199327Sridhar KatakamParticipantJust came across https://tomasz-dobrzynski.com/wordpress-gonzales. Claims to provide a simple interface to control where a plugin's assets are loaded in the front end.
January 13, 2017 at 8:14 pm #199355joycegraceParticipantFebruary 12, 2017 at 7:50 pm #201026joycegraceParticipantHi again, I have a question for troubleshooting. When I try your original code on a couple sites, it works fine.
But on a third site, I get this error: Parse error: syntax error, unexpected T_FUNCTION in /home/content/87/8254487/html/wp-content/themes/workstation-pro/functions.php on line 347
And it references this line of your code:
add_action( 'wp_print_styles', function() {
Or if I take out the code for removing styles, and just leave the one for removing the script, I get the same error on this line:
add_action( 'wp_print_scripts', function() {
Do you know why?
Find me at Joyce Grace (http://www.joycegrace.ca)
February 12, 2017 at 8:47 pm #201028Sridhar KatakamParticipantCould be due to PHP version on the server.
Try using named functions instead of anonymous functions.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.