Support » Plugin: Ajax Search Lite » load plugin core file only in one page

  • Resolved donpi73

    (@donpi73)


    Is it possible to load your plugin core files (.js, .css, etc) ONLY in one page (the search page I create to insert your shortocode) and not in all my website?

    So all other pages of my website could be more light and fast in loading…

    Thanks in advance

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    Well, there is no option, but it could be doable, programatically. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

    add_filter( 'asl_stop_loading', 'asl_stop_loading_condition', 10, 1 );
    function asl_stop_loading_condition( $stop ) {
    	if ( !DOING_AJAX ) {
    		if ( get_the_ID() != 1234 ) {
    			$stop = true;
    		}
    	}
    	
    	return $stop;
    }

    Whenever this funtion returns true, the plugin stops loading. In this example, if the current page ID is not 1234, the plugin does not load further.
    You can use this to check the current page ID or whatever condition you want.

    Best,
    Ernest M.

    • This reply was modified 2 years, 1 month ago by wpdreams. Reason: fixed code
    Thread Starter donpi73

    (@donpi73)

    Sorry,
    doesn’t work…
    All JS and CSS files of your plugin are loaded in every page of my site 🙁

    Plugin Author wpdreams

    (@wpdreams)

    Maybe a different variation, but the previous should work as well.

    add_filter('asl_stop_loading', 'asl_stop_loading_on_pages', 10, 1);
    function asl_stop_loading_on_pages($return) {
    	// Page IDs where the plugin should be loaded
    	$pages_to_load_on = array(1, 2, 3);
    	
    	// -- Don't change anything below this --
    	$url = home_url(add_query_arg(array()));
    	$current_page = url_to_postid($url);
    
    	if ( wp_doing_ajax() || $current_page === false ) {
    		return false;
    	} else {
    		return !in_array($current_page, $pages_to_load_on);
    	}
    }

    Change the $pages_to_load_on variable to the page IDs, where the plugin assets should be loaded.

    Make sure to clear the site cache as well, otherwise it may have no effect whatsoever.

    Best,
    Ernest M.

    Thread Starter donpi73

    (@donpi73)

    Thanks a lot.
    Now it’s ok! 🙂

    Thread Starter donpi73

    (@donpi73)

    I had to add a “is_admin()” at line 9, elsewhere no plugin options/settings appears in administrative backend:

    if ( wp_doing_ajax() || $current_page === false || is_admin()) {

    Plugin Author wpdreams

    (@wpdreams)

    Thank you for the feedback 🙂

    Thread Starter donpi73

    (@donpi73)

    I would have the intention to buy the PRO version …
    Do these changes also work on the PRO version of your plugin?

    Moderator Yui

    (@fierevere)

    ゆい

    Please ask all PRO related questions using plugin vendor contacts directly.
    This includes:
    * Pre-sale questions
    * PRO support
    * Refunds

    closing thread.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘load plugin core file only in one page’ is closed to new replies.