The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End WordPress javascript order

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #38616

    Well currently I started to play around with WordPress and theming stuff.
    I’m curious about the following problem:

    Well the web is full with articles on how to speed up your webpage while loading scripts at the bottom of your site and such. I though why not do it in WordPress? I don’t know how many themes I’ve installed but I could see later when you install a few plugins even sometimes if they’re not activated your Website source is full with JavaScript and inline CSS spread all over the place. I really hate this kind of behavior and that’s what I’m trying to prevent.

    I’ve created a little test to see if I could clean up things a little but then came to a problem (I’ll explain in a second!)
    While I’ll like to be organized I’ve created a small file called snippets.php which I’ve included into the functions.php of my test theme with the following code inside:

    function mytheme_dinner_time() {
    // launching operation cleanup
    add_action('init', 'mytheme_head_cleanup');

    // enqueue base scripts and styles
    add_action('wp_enqueue_scripts', 'mytheme_scripts_and_styles', 999);

    function mytheme_head_cleanup() {
    // category feeds
    remove_action( 'wp_head', 'feed_links_extra', 3 );
    // post and comment feeds
    remove_action( 'wp_head', 'feed_links', 2 );
    // EditURI link
    remove_action( 'wp_head', 'rsd_link' );
    // windows live writer
    remove_action( 'wp_head', 'wlwmanifest_link' );
    // index link
    remove_action( 'wp_head', 'index_rel_link' );
    // previous link
    remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 );
    // start link
    remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
    // links for adjacent posts
    remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
    // WP version
    remove_action( 'wp_head', 'wp_generator' );

    // loading jquery, and reply script
    function mytheme_scripts_and_styles() {
    if (!is_admin()) {
    wp_deregister_script( 'jquery' );
    wp_register_script('jquery', '' , false, '1.7.2', true);

    // Inject script files other scripts

    Well, ok now my header.php looks much cleaner as it looked before but then a problem arrived I wasn’t thinking about first.
    The problem is what to do with plugins a user might install later which are using JavaScript or they own Style Sheets?

    So they will just inject it into my “now” clean site and I’ve no way to prevent this? Well at least maybe not prevent but stay in control of it, basically a way would be fine where I could say:

    “Hey dumb plugin put your scripts only into the footer no where else!!!”

    The problem also is e.g. assume I’ve included all my theme relevant scripts incl. JQuery from Googl at the bottom.
    Now I’ll activate another plugin which will put it’s own JavaScript stuff into the head, it wont work anymore. Not sure if I’m right I was reading about sth that I could prevent e.g. a plugin from injecting jquery again but this works only if they use: wp_enqueue_script though?

    So to make a long story short I’m searching for a way to make my site look similiar to this:

    Well but to be honest I don’t think it can be done I guess kind of a script loader would be needed where you can define kind of an order mechanism (like inject after jquery first then one after another but wont work unless you know what plugin will be installed in future? )

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.