Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Gabe Shackle

    (@hereswhatidid)

    I have a filter that will be in an upcoming version that will allow you to disable the enqueuing of scripts and styles via either your theme or a plugin. The code will look something like this:

    function disable_front_scripts() {
    	return true;
    }
    add_filter( 'search_autocomplete_disable_frontscripts', 'disable_front_scripts' );
    Thread Starter gaspi

    (@gaspi)

    Thank you for your reply, i tried to make it work but no success, only errors. I also tried to make something similiar like this, but still, no success. Could you help me out how to achieve this?

    Plugin Author Gabe Shackle

    (@hereswhatidid)

    That functionality I listed isn’t actually in place yet, it will be in the next version which I’m hoping to push live in the next 3-4 days.

    Thread Starter gaspi

    (@gaspi)

    I see. Thanks for the great news ??

    Thread Starter gaspi

    (@gaspi)

    Hi. Just saw you updated your plugin so i tried to disable loading scripts you mentioned in the previous post but with no success. Could you show me an example? Where and how to add filter to disable script loading? It has to be added to the template?

    Thank you in advance!

    Plugin Author Gabe Shackle

    (@hereswhatidid)

    Here’s an example showing how to disable all scripts and styles for this plugin on the Front Page of your site:

    function sa_disable_on_home() {
    	if ( is_front_page() ) {
    		return true; // disable scripts
    	} else {
    		return false; // enable scripts
    	}
    }
    
    add_filter( 'search_autocomplete_disable_frontscripts', 'sa_disable_on_home' );

    This code would go in either your theme’s functions.php file or a plugin file if you’re loading things that way.

    Thread Starter gaspi

    (@gaspi)

    Hi, thanks for the help. If anybody interested, here is how i set it in the theme’s functions.php to enable script depending on post id:

    add_action('wp_enqueue_scripts', 'autocomplete_only_on_postID');
    
    function autocomplete_only_on_postID() {
    	global $post;
    	$post_id = $post->ID;
    
    	if ( $post_id == XX ) {
    		return false; // enable scripts
    	} else {
    		return true; // disable scripts
    	}
    }
    
    add_filter( 'search_autocomplete_disable_frontscripts', 'autocomplete_only_on_form' );
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Loading JS and styles only when it's necessary’ is closed to new replies.