Title: Only load when needed
Last modified: August 24, 2016

---

# Only load when needed

 *  [snakefoot](https://wordpress.org/support/users/snakefoot/)
 * (@snakefoot)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/only-load-when-needed/)
 * Had the plugin profiler enabled, and it showed that Search Everything took most
   cpu-time.
 * Changed the plugin, so it only loaded when needed, and the profiler became happy:
 * function se_initialize_plugin($query) {
    global $SE; if (!isset($SE) && $query-
   >is_search()) $SE = new SearchEverything(); } add_filter(‘parse_query’, ‘se_initialize_plugin’);
 * function se_initialize_plugin_admin() {
    global $SE; if (is_admin()) $SE = new
   SearchEverything(); } add_action(‘wp_loaded’,’se_initialize_plugin_admin’);
 * function se_global_head() {
    if (is_admin() || is_search()) include(se_get_view(‘
   global_head’)); } add_action(‘wp_head’, ‘se_global_head’);
 * function se_enqueue_styles() {
    if (is_admin() || is_search()) wp_enqueue_style(‘
   se-link-styles’, SE_PLUGIN_URL . ‘/static/css/se-styles.css’); }
 * add_action(‘wp_enqueue_scripts’, ‘se_enqueue_styles’);
 * [https://wordpress.org/plugins/search-everything/](https://wordpress.org/plugins/search-everything/)

Viewing 1 replies (of 1 total)

 *  [PetraP](https://wordpress.org/support/users/petrap/)
 * (@petrap)
 * [11 years, 1 month ago](https://wordpress.org/support/topic/only-load-when-needed/#post-5997616)
 * Hey,
 * thanks for publishing the code – hopefully someone else will find it useful too.
 * Once again, thanks for taking the time for the feedback, take care and have a
   lovely day,
 * Petra

Viewing 1 replies (of 1 total)

The topic ‘Only load when needed’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/search-everything_242529.svg)
 * [Search Everything](https://wordpress.org/plugins/search-everything/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/search-everything/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/search-everything/)
 * [Active Topics](https://wordpress.org/support/plugin/search-everything/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/search-everything/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/search-everything/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [PetraP](https://wordpress.org/support/users/petrap/)
 * Last activity: [11 years, 1 month ago](https://wordpress.org/support/topic/only-load-when-needed/#post-5997616)
 * Status: not resolved