Home Forums Plugin Support WP User Frontend Pro Loading of scripts

This topic is: resolved

Tagged: 

This topic contains 5 replies, has 5 voices, and was last updated by  Chris Swede 4 years, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18737

    Jonas
    Member
    Post count: 1

    Hi,

    currently WPUF is loading all Javascript and CSS files on all WordPress pages. Is that really necessary? Why not loading it only when a shortcode is included in the current page as you do it with the plugin scripts?

    There was also a forum post about it one year ago in the WordPress forum:
    http://wordpress.org/support/topic/plugin-wp-user-frontend-wpuf-breaks-the-themes-layout

    Regards
    Jonas

    #18749

    Mahi
    Member
    Post count: 1555

    Hello,

    Its been fixed long time back. Check WPUF -> Settings ->Load Scripts

    you can turn if off here.

    #18750

    Jonas
    Member
    Post count: 1

    Hello,

    as far as I can see in the code (version 2.1.9) it was only changed for the plugin scripts, but not for the scripts of wpuf itself. The Google Maps API, frontend-forms.css and frontend-form.js are still loaded on every WordPress page independent of the “Load Scripts” option.

        function enqueue_scripts() {
            
            $path = plugins_url( '', __FILE__ );
            $scheme = is_ssl() ? 'https' : 'http';
            
    <strong>        wp_enqueue_script( 'google-maps', $scheme . '://maps.google.com/maps/api/js?sensor=true' );
            wp_enqueue_style( 'wpuf-css', $path . '/css/frontend-forms.css' );
            wp_enqueue_script( 'wpuf-form', $path . '/js/frontend-form.js', array('jquery') );</strong>
            
            if ( wpuf_get_option( 'load_script', 'wpuf_general', 'on') == 'on') {
                $this->plugin_scripts();
            } else if ( wpuf_has_shortcode( 'wpuf_form' ) || wpuf_has_shortcode( 'wpuf_edit' ) || wpuf_has_shortcode( 'wpuf_profile' ) || wpuf_has_shortcode( 'wpuf_dashboard' ) ) {
                $this->plugin_scripts();
            }
        }

    Regards
    Jonas

    #23291

    Daniel
    Member
    Post count: 8

    I agree with this – google maps scripts are loaded on every page.
    I see no point in this, as it should only be loaded if required. Right now it slows down my page with several seconds.

    Why are they not loaded inside the if-statement that controls the plugin scripts?

    #23472

    Sekander Badsha
    Member
    Post count: 2067

    Mahi have said the fix above. You can control from settings whether to load the scripts in every page or not. Please see the comment above.

    #23871

    Chris Swede
    Member
    Post count: 56

    Hi, please put this in your theme's functions.php

    function disable_wpuf_scripts() {
        // Remove scripts from all pages except where needed - match IDs to WPUF page IDs
        if( ! is_page(array('278','279','280')) ) {
            wp_dequeue_style( 'wpuf-css' );
    	wp_dequeue_script( 'wpuf-form' );
    	wp_dequeue_script( 'google-maps' );
        }
    }
    // Set priority to run after scripts are enqeued by the plugin
    add_action( 'wp_enqueue_scripts', 'disable_wpuf_scripts', 100 );
Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Loading of scripts’ is closed to new replies.