Come caricare css nel footer
1 risposta
- voti
-
- 2015-05-01
In realtàtuttigli stili dovrebberoessereinseritinell'intestazione.Quindi WordPressnon ha unparametroperfarlonellafunzione
wp_enqueue_style
,perchétradizionalmentetuttigli stili venivano aggiuntinellahead
.Di recente,molti siti sonopassati a un sistemain cuigli stili "abovethefold" critici vengono caricatiin testa,mentre altri stili vengono caricatinelpiè dipagina.Quindiecco unmodoperfarlo:puoi usare lafunzione
print_late_styles()
che viene chiamata apiè dipagina.Hai solobisogno di accodarei tuoi stili quando l'intestazione ègiàpassata.Quindi ènecessariotrovare un hook chiamatoin ognipaginae dopo l'hook
wp_head
.Adesempioget_footer
potrebbeessere uno.function prefix_add_footer_styles() { wp_enqueue_style( 'your-style-id', get_template_directory_uri() . '/stylesheets/somestyle.css' ); }; add_action( 'get_footer', 'prefix_add_footer_styles' );
Actually all styles should be placed in header. So WordPress doesn't have a parameter for doing this in the
wp_enqueue_style
function, because traditionally all styles were added in thehead
. Recently, many sites have moved to a system where critical "above the fold" styles are loaded in the head, while other styles are loaded in the footer.So here is a way to to this: You can use
print_late_styles()
function which is called in footer. You just need to enqueue your styles when header is already passed.So you need to find some hook which is called on each page and after
wp_head
hook. For exampleget_footer
could be one.function prefix_add_footer_styles() { wp_enqueue_style( 'your-style-id', get_template_directory_uri() . '/stylesheets/somestyle.css' ); }; add_action( 'get_footer', 'prefix_add_footer_styles' );
-
Ma se voglioforzare lo stilenelpiè dipagina comepossofare?Non c'è davveromodoperfarlo?But if i want to force the style in the footer how could i do? There is really no way to do that?
- 0
- 2015-05-01
- Giulio Bambini
-
[`print_late_styles ()`] (https://developer.wordpress.org/reference/functions/print_late_styles/)potrebbeessere usatoper questo,non che dovresti,però,»* Stampagli stili che sono statimessiin codatroppotardiperilHTML head. * «.@GiulioBambini[`print_late_styles()`](https://developer.wordpress.org/reference/functions/print_late_styles/) could be used for that, not that you should though, it »*Prints the styles that were queued too late for the HTML head.*«. @GiulioBambini
- 0
- 2015-05-01
- Nicolai
-
@Emetroppotrestiessere cosìgentile damostrarmi unesempio di codice sullafunzionalitàprint_late_style?@Emetrop could you please be so kind to show me an example of code about print_late_style functionality?
- 0
- 2015-05-01
- Giulio Bambini
-
In realtà è unmito chegli stili ** debbano **esserenellatesta,gli stili che sono **essenziali **peril rendering dellapaginainiziale dovrebberoesserenellatesta.Altri stilinon così criticipossonoessere caricatinellaparteinferioreper ottimizzare la velocità di caricamento dellapagina.Actually its a myth that styles **need** to be in the head, styles that are **essential** for the initial page render should be in the head. Other not so critical styles can be loaded at the bottom to optimize for page-load speed.
- 24
- 2017-02-25
- NextGenThemes
Stavo cercando di spostareil carico delmio style.cssnelpiè dipagina delmiotema wordpress.Hogiàfatto qualcosa di simile con 2filejse funzionabene,si caricanonelpiè dipagina:
Ora stavo cercando di spostare apiè dipagina anche style.css,e mantenere solo alcune regole CSSinlineneltag.Hoprovato wp_enqueue_stylema sembra chenonfunzionibene perme.
Qualcunopotrebbe aiutarmi atrovare una soluzioneintelligente?