• Resolved rmsgreig

    (@rmsgreig)


    Hello I am looking at being able to only run the js required for OpenTicket when it is on the correct pages like the calendar and the events. I believe you can do this by adding a function to functions php like so:

    // Call the function
    function geoffgraham_enqueue_stuff() {
    
      // Specify the conditional tag
      if ( is_page( 'new-page' ) ) {
            
        // If page matches, then load the following files
        wp_enqueue_style('new-styles.css', get_template_directory_uri().'/path/to/new-styles.css', false ,'1.0', 'all' );
        wp_enqueue_script('new-scripts.js', get_template_directory_uri().'/path/to/new-scripts.js', false ,'1.0', 'all' );
    
       // If the condition tag does not match...
       } else {
    
       // ...then load the global files instead
        wp_enqueue_style('style.css', get_template_directory_uri().'/path/to/style.css', false ,'1.0', 'all' );
        wp_enqueue_script('scripts.js', get_template_directory_uri().'/path/to/scripts.js', false ,'1.0', 'all' );
      }
    }
    
    // Hook into the WordPress Function
    add_action( 'wp_enqueue_scripts', 'geoffgraham_enqueue_stuff' );

    but i see in the code files I have checked that there are register_script and admin_enqueue_script. Could you tell me which wp_enqueue_script I need to use?
    Many Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author loushou

    (@loushou)

    Hey @rmsgreig,

    Most of the scripts you are talking about, already load only on the page that they are used on. Here is a breakdown of where you can find the code to model your code after (all paths are inside of the /wp-content/plugins/opentickets-community-edition/ directory):

    Calendar
    The calendar’s scripts already only load on pages that have calendars. This is done in the code that loads the scripts, by first checking if the current page has a calendar on it, and then second loading the scripts if it does. You can find the code in inc/core/calendar.class.php @ add_assets() (roughly line 266 in current version).

    Events
    For general admission events (the only type of event you can have without an extension), the javascript used to control the interface used to select your tickets, again only loads on the event pages. This is again controlled by logic that first checks if the current page is an event page, whether the event has all the required information needed to render the interface. Then only after those checks pass, it loads the javascript. You can see this logic you need to emulate in inc/event-area/general-admission-area-type.class.php @ enqueue_assets() (roughly line 106).

    Admin Assets
    Many of the features have respective admin pages. Like the frontend pages, these pages all have checks to make sure that the assets belong, before the assets are actually loaded.

    Loaded only on admin pages that need it:
    event posts inc/core/post-type.class.php @ load_edit_page_assets() (1063)
    order pages inc/event-area/general-admission-area-type.class.php @ enqueue_assets (106)
    order pages inc/event-area/post-type.class.php @ load_assets_edit_order (1486)
    event areas inc/event-area/post-type.class.php @ enqueue_admin_assets_event_area (214)
    event posts inc/event-area/post-type.class.php @ enqueue_admin_assets_event (230)
    venue pages inc/venues/post-type.class.php @ load_venue_admin_assets_later (330)
    event posts inc/venues/post-type.class.php @ load_event_venue_assets (353)

    Loaded on all pages in admin:
    calendar inc/core/calendar.class.php @ load_admin_assets() (233)

    Hope this helps,
    Loushou

    Thread Starter rmsgreig

    (@rmsgreig)

    there are still a couple of scripts that show up on pages that don’t have the events, I am trying to remove them like so:

    	wp_dequeue_script('open-tickets-community-edition', plugins_url('assets/js/libs/moment-timezone/moment-timezone-all-years.js'));
    		wp_dequeue_script('open-tickets-community-edition',   plugins_url('assets/js/libs/fullcalendar/lib/moment.min.js'));

    but having no success so far
    thanks
    Rachel

    Plugin Author loushou

    (@loushou)

    Hi @rmsgreig,

    Sorry it seems I missed this followup too.

    Both of the scripts in question should not show up on any event pages at all. They should only show on pages that have the ‘event calendar’ on them (like your frontend calendar page, or any edit-post pages for events in the admin).

    With that in mind, if you are certain that these scripts are loading on pages that they do not need to on your site, you can dequeue them using these lines:

    wp_dequeue_script( 'moment-js' );
    wp_dequeue_script( 'moment-core-js' );

    The wp_dequeue_script() function only requires the script unique name (not the plugin name), which is the first parameter. Both of those scripts are registered in opentickets-community-edition/inc/core/calendar.class.php around line 138, and both are only used by the calendar portion of the site currently, in community edition. I’m not sure how they could be loading on any other pages, but this should help you not load them.

    Hope this helps,
    Loushou

    Thread Starter rmsgreig

    (@rmsgreig)

    Hello,
    I have tried the dequeue’s above but they are still appearing, would you have any other ideas that may work?

    Thanks
    Rachel

    Plugin Author quadshot

    (@quadshot)

    Hi Rachel, have you tried clearing your browser cache? Sometimes this may cause code changes not to show. If the issue is still present after this we advise that you create a support ticket at Your Opentickets My Account page and we can take a closer look at your issue. Thanks Rachel

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘wp_enqueue_script page speed help’ is closed to new replies.