wp_head wp_footer Prioritäten Abfrage javascript oder style

  • Hallo,

    ich habe die Javascripts mit jquery sowie die CSS-Dateien vom wp_head in den wp_footer verlegt. Funktioniert auch. Jetzt möchte ich, dass im Footer die CSS-Dateien vor den Javascripten aufgerufen werden. Gibt es da eine Möglichkeit?

    Meine Programmierung in der funtion.php sieht im Moment so aus:


    • Anzeige

    Hallo!

    Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.

    • ✔️ Schnelle Ladezeiten (optimiert für WordPress & Co.)
    • ✔️ Deutsche Server & DSGVO-konform
    • ✔️ Persönlicher Support (kein 0815-Ticket-System)

    Mehr erfahren

  • wieso hast du die css in den Footer gelegt, die gehören doch in den Header.

    [size=10]Bitte immer zuerst die Forensuche nutzen und erst danach Deine Fragen hier im Forum stellen, denn sehr vieles wurde schon mehrfach beantwortet. Bitte dabei auch die Forenregeln beachten.
    Kein Support per PN - Fragen gehören ins Forum.[/SIZE]
    [size=8]Wenn du eine weise Antwort verlangst, musst du vernünftig fragen. (Johann Wolfgang von Goethe)[/SIZE]

  • PHP
    add_action('wp_footer', 'wp_enqueue_style', 5);

    die Ziffer zb '5' gibt die Reihenfolge an=> hilft das als Tipp weiter?

  • Leider nicht. Ich habe jetzt alle Befehle von 1 bis 6 in der gewüschten Reihenfolge durchnummereiert. Jetzt wird wieder alles im head angezeigt.


    [COLOR=#000000][COLOR=#FF8000]/* Remove scripts and styles form head too footer */

    [/COLOR][COLOR=#0000BB]remove_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_head'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_enqueue_style'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]);[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]
    [/COLOR][COLOR=#0000BB]remove_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_head'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_print_scripts'[/COLOR][COLOR=#007700][/COLOR][/COLOR][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700], [/COLOR][COLOR=#0000BB]2[/COLOR][/COLOR][/COLOR][/COLOR]);
    [/COLOR][COLOR=#0000BB]remove_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_head'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_print_head_scripts'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]3[/COLOR][COLOR=#007700]);
    [/COLOR][COLOR=#0000BB]remove_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_head'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_enqueue_scripts'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]4[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
    [COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#0000BB]remove_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_head'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'ratings_javascripts_header'[/COLOR][COLOR=#007700][/COLOR][/COLOR][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700], [/COLOR][COLOR=#0000BB]5[/COLOR][/COLOR]);[/COLOR][/COLOR][/COLOR][/COLOR]

    [/COLOR][COLOR=#0000BB]add_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_footer'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_enqueue_style'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]1[/COLOR][COLOR=#007700]);[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]
    [/COLOR][COLOR=#0000BB]add_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_footer'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_print_scripts'[/COLOR][COLOR=#007700], 2[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#0000BB][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]);[/COLOR][/COLOR]
    [COLOR=#000000][COLOR=#0000BB][COLOR=#000000][COLOR=#0000BB]add_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_footer'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_print_head_scripts'[/COLOR][COLOR=#007700], 3[/COLOR][COLOR=#0000BB][/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
    add_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_footer'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'wp_enqueue_scripts'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]4[/COLOR][COLOR=#007700]);[/COLOR][/COLOR]
    [COLOR=#000000][COLOR=#0000BB]add_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'wp_footer'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'ratings_javascripts_header', [/COLOR][/COLOR][COLOR=#000000][COLOR=#DD0000][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]5[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#0000BB][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#007700]);[/COLOR][/COLOR][COLOR=#000000][COLOR=#007700]


    [/COLOR][COLOR=#FF8000]/* Remove jquery from head too footer */

    [/COLOR][COLOR=#007700]if ( ![/COLOR][COLOR=#0000BB]is_admin[/COLOR][COLOR=#007700]() ) [/COLOR][COLOR=#0000BB]wp_deregister_script[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'jquery'[/COLOR][/COLOR][COLOR=#000000][COLOR=#DD0000][COLOR=#000000][COLOR=#DD0000], [/COLOR][/COLOR][COLOR=#000000][COLOR=#DD0000][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]6[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#0000BB][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#007700][/COLOR][/COLOR][/COLOR][COLOR=#007700]);


    function [/COLOR][COLOR=#0000BB]my_init[/COLOR][COLOR=#007700]()
    {
    if (![/COLOR][COLOR=#0000BB]is_admin[/COLOR][COLOR=#007700]())
    {
    [/COLOR][COLOR=#0000BB]wp_deregister_script[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'jquery'[/COLOR][COLOR=#007700][/COLOR][/COLOR][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#DD0000], [/COLOR][/COLOR][COLOR=#000000][COLOR=#DD0000][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]6[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#0000BB][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][COLOR=#007700][/COLOR][/COLOR]);

    [/COLOR][COLOR=#FF8000]// Load the copy of jQuery that comes with WordPress
    // The last parameter set to TRUE states that it should be loaded
    // in the footer.
    [/COLOR][COLOR=#0000BB]wp_register_script[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'jquery'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'/wp-includes/js/jquery/jquery.js'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]FALSE[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'1.11.0'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]TRUE[/COLOR][COLOR=#007700]);

    [/COLOR][COLOR=#0000BB]wp_enqueue_script[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'jquery'[/COLOR][COLOR=#007700][/COLOR][/COLOR][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#DD0000], [/COLOR][/COLOR][COLOR=#000000][COLOR=#DD0000][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][COLOR=#000000][COLOR=#007700][/COLOR][COLOR=#0000BB]6[/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR][/COLOR]);
    }
    }
    [/COLOR][COLOR=#0000BB]add_action[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]'init'[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]'my_init'[/COLOR][COLOR=#007700]); [/COLOR][/COLOR]

  • Hat noch jemand eine Idee, warum meine Programmierung nicht funktioniert? Bin Monikas Rat gefolgt, und habe die Prioritäten der Abfragen durch die Zifferfolge 1-6 festgelegt.

  • Hi, hat niemand eine Idee? Ich werde nun einen Programmierer beauftragen, und das Ergebnis dann hier posten. Allerdings wird sich der Programmierer über den Miniauftrag nicht besonders freuen. Das Rechnungschreiben dauert für den Profi wahrscheinlich länger als der Auftrag selbst.

  • warum probierst du es nicht einfach mal durch, z.B. so:

    PHP
    add_action('wp_footer', 'wp_enqueue_style', 1);
    add_action('wp_footer', 'ratings_javascripts_header');
    add_action('wp_footer', 'wp_print_scripts', 5);
    add_action('wp_footer', 'wp_enqueue_scripts', 5);
    add_action('wp_footer', 'wp_print_head_scripts', 5);


    1 ist dabei die höchste Prio, d.h. müsste dann vor der 5 stehen.

    [size=10]Bitte immer zuerst die Forensuche nutzen und erst danach Deine Fragen hier im Forum stellen, denn sehr vieles wurde schon mehrfach beantwortet. Bitte dabei auch die Forenregeln beachten.
    Kein Support per PN - Fragen gehören ins Forum.[/SIZE]
    [size=8]Wenn du eine weise Antwort verlangst, musst du vernünftig fragen. (Johann Wolfgang von Goethe)[/SIZE]

  • folgendes:

    bevor du den Auftrag gibts,

    setz das CSS beinhart "hart verlinkt" in den Footer, logge dich aus,
    lösche alle Cookies und alles von deiner Site aus dem Browser

    und dann kontrolliere, ob es nicht "flackert" oder das CSS sehr lange braucht bis es "wirkt".

    Ich seh öfter Sites, wo das gemacht wurde und meist lädt dann das CSS sehr spät und das hinterläßt einen bescheidenen "ersten Eindruck".

    Vergiss mal was du machtest und hol dir das Plugin Autooptimize und schau,ob du damit nicht einfachere und bessere Lösungen findest.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!