Okay
  Public Ticket #1226059
Script Priority -> add_action( 'wp_enqueue_scripts', 'my_scripts', …
Closed

Comments

  •  2
    Stephan started the conversation

    Hello,

    could you provide the function to set a priority to the addon scripts?
    I'd like to load my created addons/scripts before other plugins, but in the settings there is only the general option to say "Js Always in Footer - yes - no". In this case the scripts are loaded too late. I want to load them earlier.

    At the moment the scripts aren't loaded with "enqueue_scripts", right?


    Here is a description for priority:
    https://stackoverflow.com/questions/19913960/enqueue-wordpress-plugin-scripts-below-all-other-js


    kind regards,

    Stephan


  •   Max replied privately
  •   Stephan replied privately
  •   Max replied privately
  •  2
    Stephan replied

    Hey Max,

    well. All we need is a unique name for the loaded script. If we have such a name, we can change the priority.

    Here is an example for overwriting the priority of fontawesome:


    function overwrite_font_awesome()
    {    
        wp_dequeue_style( 'font-awesome' );
        wp_deregister_style( 'font-awesome' );    
        
        wp_register_style ('font-awesome', get_stylesheet_directory_uri() . '/font-awesome/css/font-awesome.min.css','','4.7');
        wp_enqueue_style('font-awesome');
    }
    add_action( 'wp_enqueue_scripts', 'overwrite_font_awesome', 1 );


    -> because we have the name "font-awesome" we can deregister/dequeue everything that was placed before.
    -> now we can can add it again and with the priority 1 in "add_action( 'wp_enqueue_scripts', 'overwrite_font_awesome', 1 )" it is loaded before all other elements.
    Perhaps you can define it in your php scripts and make an option in the plugin builder where you can set/type a priority.


    Kind regards,

    Stephan

  •   Max replied privately