come aggiungere la versione di style.css in wordpress
-
-
Ecco unplugin https://wordpress.org/plugins/wp-css-version-history/che aggiungerà automaticamente unnumero di versionenelfoglio di stile.Crea unnuovofoglio di stile che viene caricatoper ultimo.Non ènecessario svuotare la cacheper visualizzare lemodifiche.Utilizza Wordpressintegratonell'editor CSSe bloccofile utenteper la collaborazionein team.Here is a plugin https://wordpress.org/plugins/wp-css-version-history/ that will automatically append a version number in the stylesheet. It creates a new stylesheet which is loaded last. No need to clear cache to see changes. Uses Wordpress built in CSS editor and user file lock for team collaboration.
- 0
- 2018-05-14
- Brian Holzberger
-
9 risposta
- voti
-
- 2013-03-14
Ilnumero di versione è unparametro di
wp_enqueue_style()
.Comeperil Codex,eccotuttii parametri che
wp_enqueue_style
accetta.wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Quindi,adesempio,per caricare unfoglio di stile con unnumero di versione,devifare quanto segue:
function wpa_90820() { wp_enqueue_style('my-styles', get_stylesheet_directory_uri() .'/my-styles.css', array(), '1.0' ); } add_action('wp_enqueue_scripts', 'wpa_90820');
Version number is a parameter of
wp_enqueue_style()
.As per the Codex, here are all the parameters that
wp_enqueue_style
accepts.wp_enqueue_style( $handle, $src, $deps, $ver, $media );
So for example to load a stylesheet with a version number you'd do the following:
function wpa_90820() { wp_enqueue_style('my-styles', get_stylesheet_directory_uri() .'/my-styles.css', array(), '1.0' ); } add_action('wp_enqueue_scripts', 'wpa_90820');
-
quando lofaccio,viene caricato ancheil vecchio style.css.Come rimuoverlo?when i do this the old style.css is also loading. How to remove it?
- 0
- 2013-03-14
- Toretto
-
@VinodDalvi cosaintendipermaniglia.Non lo so,sononuovo di Wordpressperfavore.@VinodDalvi what do you mean by handle. i don't know about it ,i m new to wordpress please me.
- 0
- 2013-03-14
- Toretto
-
@Toretto Oiltuotema lo sta codificando come hardcodedin header.php o ancheiltuotema lo sta accodando con un handle diverso (ilprimoparametro).La soluzione dipende anche se staimodificando direttamenteilfunctions.php deltuotema o se hai creato un childtheme.@Toretto Either you theme is hard-coding it in header.php or your theme is also enqueing it with a different handle (the first parameter). The solution also depends on if you are directly editing your theme's functions.php or if you've created a child theme.
- 1
- 2013-03-14
- helgatheviking
-
@Toretto,$ handle èmostratonellamia rispostae descritto anchenel link che hofornito allapagina del Codexper `wp_enqueue_style`,perfavorefaii compiti.@Toretto, $handle is shown in my response and also described in the link I provided to the Codex page for `wp_enqueue_style` please do your homework.
- 0
- 2013-03-14
- helgatheviking
-
@helgatheviking comeposso conoscereil vecchionome delgestore.@helgatheviking how can i know the old handler name.
- 0
- 2013-03-14
- Toretto
-
@Toretto Seiltuotema usa `wp_enqueue_style ()`per caricareilfoglio di stilein questione,il suo handle èil *primo *parametro.Seiltuotema sta codificandoilfoglio di stilein header.php,alloranon avrà un handle.@Toretto If your theme is using `wp_enqueue_style()` to load the stylesheet in question then it's handle is the *first* parameter. If your theme is hard-coding the stylesheet in header.php then it won't have a handle.
- 1
- 2013-03-14
- helgatheviking
-
ok ho capito,ho sostituito lamiafunzione di stile deltemapredefinitae inizia afunzionare.graziemille @helgatheviking.ok i got it, i have replace my default theme style function and it start working.thanks a lot @helgatheviking.
- 0
- 2013-03-14
- Toretto
-
- 2017-11-17
Invece di cablare la versione,potrestitrovaremeglioin alcuni casi rivedere dinamicamenteiltuofoglio di stile così ogni volta che lo cambi,cambia automaticamentee aggiornaimmediatamente la cache delbrowser senza dovermodificareiltuofunctions.phppiùe più volte.
Puoi usarefilemtime ()perfarlo.Ecco comefarloin uno stilefiglio chefa riferimento aparent_style
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), filemtime( get_stylesheet_directory() . '/style.css' ) );
Instead of hardwiring the version, you might find it better in some instances to dynamically version your stylesheet so whenever you change it, it automatically changes and refreshes the browser cache immediately without having to edit your functions.php over and over again.
You can use filemtime() to do that. Here is how to do that in a child-style that references the parent_style
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( $parent_style ), filemtime( get_stylesheet_directory() . '/style.css' ) );
-
Neltempo,sono arrivato apreferire le versioni deitemi,ma è unabuonaidea usarefilemtime () qui,senon si dispone di unapratica coerente di controllo delle versioni deltema.Over time, I've come to prefer theme versions, but it's a great idea to use filemtime() here, if one doesn't have a consistent theme versioning practice.
- 0
- 2018-03-14
- jgangso
-
- 2019-10-01
Se sei uno sviluppatore ditemi,potresti volerforzareil ricaricamento delletue risorse quandoeseguiilpush dellanuova versione.
Quindiil controllo delle versioni di untema vieneeseguitoin
style.css
/* Nometema:ilnome deltema Versione: 1.0.2 */ In cima altuo
functions.php
:$theme=wp_get_theme (); define ('THEME_VERSION',$theme- > Version);//ottiene la versione scrittaneltuo style.css
Successivamente,quando accodi CSS o JS,utilizza
THEME_VERSION
come quarto argomento:funzionetheme_styles () { wp_enqueue_style ('main',get_template_directory_uri (). '/css/main.css',[],THEME_VERSION,'all'); } add_action ('wp_enqueue_scripts','theme_styles');
Verrà visualizzatonellapagina:
.../nome-tema/css/main.css? ver=1.0.2
È utile quando haipiù risorse di cuipreoccupartie non vuoimodificarlemanualmente.
If you are a theme developer, you might want to force reload of your assets when you push new version.
So versioning of a theme is done in
style.css
/* Theme Name: Your Theme Name Version: 1.0.2 */
At the top of your
functions.php
:$theme = wp_get_theme(); define('THEME_VERSION', $theme->Version); //gets version written in your style.css
Later when you enqueue CSS or JS, use
THEME_VERSION
as fourth argument:function theme_styles() { wp_enqueue_style('main', get_template_directory_uri().'/css/main.css', [], THEME_VERSION, 'all'); } add_action('wp_enqueue_scripts', 'theme_styles');
Will output to the page:
.../your-theme-name/css/main.css?ver=1.0.2
Gets handy when you have more assets to care about and don't want to change them manually.
-
- 2013-03-14
Puoi ottenere ciò utilizzando uno dei seguentimodi:
1) Aggiungiil seguentetagnelfile header.php deltema.
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>'?v=1.2" type="text/css" media="all" />
2) Aggiungiil seguente codicenelfilefunctions.php deltema.
function theme_styles() { // Register the style like this for a theme: // (First the unique name for the style (custom-style) then the src, // then dependencies and ver no. and media type) wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css', array(), '1.2', 'all' ); } add_action('wp_enqueue_scripts', 'theme_styles');
Per ulterioriinformazioni,vedere questapagina.
You can achieve this using one of the following ways :
1) Add following tag in header.php file of the theme.
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>'?v=1.2" type="text/css" media="all" />
2) Add following code in functions.php file of the theme.
function theme_styles() { // Register the style like this for a theme: // (First the unique name for the style (custom-style) then the src, // then dependencies and ver no. and media type) wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css', array(), '1.2', 'all' ); } add_action('wp_enqueue_scripts', 'theme_styles');
For more information see this page.
-
quando lofaccio,viene caricato ancheil vecchio style.css.Come rimuoverlo?when i do this the old style.css is also loading. How to remove it?
- 0
- 2013-03-14
- Toretto
-
Qual è l'handle di old style.css?What is the handle of old style.css?
- 0
- 2013-03-14
- Vinod Dalvi
-
senon riesci atrovare l'handle,copiae incolla l'intero URL style.css qui .. lo otterrò da lì ...if you are not able to find the handle then just copy and paste the whole style.css url here.. i will get it from there...
- 0
- 2013-03-14
- Vinod Dalvi
-
Oppurepuoi dirmi qual èilnome deltuotema oilnome della cartella deitemi?Or can you tell me whats your theme name or theme's folder name?
- 0
- 2013-03-14
- Vinod Dalvi
-
ok ho capito,devo sostituire lamiafunzione di stile deltemapredefinitoe inizia afunzionare.grazie. + 1 dapartemia.ok i got it, i have replace my default theme style function and it start working.thanks.+1 from me.
- 0
- 2013-03-14
- Toretto
-
Benvenuto .... :)Welcome .... :)
- 1
- 2013-03-14
- Vinod Dalvi
-
- 2015-06-08
ilmodomiglioreper caricare cssneltuotema wordpress èil seguente codiceneltuofilefunctions.php:
function theme_styles() { global $ver_num; // define global variable for the version number $ver_num = mt_rand() // on each call/load of the style the $ver_num will get different value wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css', array(), $ver_num, 'all' ); } add_action('wp_enqueue_scripts', 'theme_styles');
Questo èilmodogiustoper caricaregli stilineltuotemaed è ancheilmiglioreper scopi dimessain scena/testperché ogni aggiornamentofornirà la versione aggiornata dello stile.
Se vuoievitareil caricamento alprimomodo,puoi usare questa versione abbreviatae inserire la seguente riganeltuofile header.phpe otterrai lo stesso risultato:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?ver=' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
Saluti
the best way to load css into your wordpress theme is the following code in your functions.php file:
function theme_styles() { global $ver_num; // define global variable for the version number $ver_num = mt_rand() // on each call/load of the style the $ver_num will get different value wp_enqueue_style( 'style-css', get_template_directory_uri() . '/style.css', array(), $ver_num, 'all' ); } add_action('wp_enqueue_scripts', 'theme_styles');
This is the right way to load the styles in your theme and also it's the best for staging/testing purposes because each refresh will deliver the updated version of the style.
If you want to avoid the loading 1st way, you can use this shorted version and place the following line into your header.php file and will get the same result:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?ver=' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
Cheers
-
- 2017-03-16
Prova questo:
Aggiungilo afunctions.php
function autoVer($filename){ $url = get_template_directory_uri() . $filename; $file = get_template_directory() . $filename; if ( file_exists($file)) { return $url . '?v=' .md5(date("FLdHis", filectime($file)) . filesize($file)); } clearstatcache(); }
Aggiungilo all'intestazione o alpiè dipagina -> autoVer ('/js/main.js');
Try this:
Add this to functions.php
function autoVer($filename){ $url = get_template_directory_uri() . $filename; $file = get_template_directory() . $filename; if ( file_exists($file)) { return $url . '?v=' .md5(date("FLdHis", filectime($file)) . filesize($file)); } clearstatcache(); }
Add this to the header or footer -> autoVer('/js/main.js');
-
- 2020-02-28
Contrariamente aimetodipresentatifinora,credo siameglio usareilnumero di versione che appare all'inizio deltuofile style.css:
// style.css /** Theme Name: My theme ... Version: 1.2.3 ... **/
Per utilizzare la versione deltemaneltuo css,aggiungi quanto segue altuo scriptfunctions.php (oequivalente):
<?php wp_enqueue_style( 'my-theme', get_stylesheet_directory_uri() . '/style.css', [], wp_get_theme()->get('Version') );
Ciò significa che,dopo avermodificatoilfile style.css,tutto ciò che devifare è cambiareilnumero di versionenellaparte superiore dello stessofileper vedere lemodifichenelfrontend.
Seesamini la sezioneprincipale dell'HTML deltema,vedrai quanto segue:
<link rel='stylesheet' id='my-theme-css' href='... style.css?ver=1.2.3' type='text/css' media='all' />
Contrary to the methods presented so far, I believe it is better to use the version number which appears at the top of your style.css file:
// style.css /** Theme Name: My theme ... Version: 1.2.3 ... **/
To use the theme's version in your css, add the following to your functions.php (or equivalent) script:
<?php wp_enqueue_style( 'my-theme', get_stylesheet_directory_uri() . '/style.css', [], wp_get_theme()->get('Version') );
This means that, after you edit your style.css file, all you need to do is to change the version number at the top of the same file to see the changes in the frontend.
If you examine the head section of the theme's HTML you will see the following:
<link rel='stylesheet' id='my-theme-css' href='... style.css?ver=1.2.3' type='text/css' media='all' />
-
- 2020-07-21
Un'altra soluzione senon riesci ancora a capirlo,è cambiareilnome delfile style.css deltuo childtheme,adesempio,style2.csse poi cambiarlonelfilefunctions.php deltuo childtheme,comemostratosotto:
wp_enqueue_style( 'style', get_stylesheet_directory_uri() .'/style2.css' );
Ciòfarà sì che Wordpress richiedae fornisca unnuovofile CSSperiltuo sito web.
Another solution if you can't figure it out yet, it's to change the filename of your child theme's style.css to, for example, style2.css and then change it on your child theme's functions.php file, as shown below:
wp_enqueue_style( 'style', get_stylesheet_directory_uri() .'/style2.css' );
This will cause Wordpress to request and serve a new CSS file for your website.
-
- 2013-06-05
Questo è unmodo abbastanza sempliceper ottenereilnumero di versione chiamando la funzione
bloginfo($show)
due volte.Primoperilfoglio di stilee secondoperilnumero di versione.<link rel="stylesheet" id="style-css" href="<?php bloginfo('stylesheet_url'); ?>?ver=<?php bloginfo('version'); ?>" type="text/css" media="all" />
Questo ètutto quello che c'è dafare.Spero che aiuti o sia utile.Puoiesaminaretuttii parametri disponibilie vedere cosapuoiprodurre con lafunzione
bloginfo()
.Ignorailmio commentopoiché @Ravs ha segnalatoilmioerrore relativo alparametro "versioni"per lafunzionebloginfo ().Stampaeffettivamenteilnumero di versione di Wordpress.
This is pretty straight up way of getting the version number by calling the function
bloginfo($show)
twice. First for the stylesheet and secondly for the version number.<link rel="stylesheet" id="style-css" href="<?php bloginfo('stylesheet_url'); ?>?ver=<?php bloginfo('version'); ?>" type="text/css" media="all" />
Thats all there is to it. Hope that helps or is useful. You can go through all the parameters available and see what you can output with the
bloginfo()
function.Ignore my comment since @Ravs has pointed out my error regarding the 'versions' parameter for the bloginfo() function. It does indeed print the Wordpress version number.
-
Penso chenon sia la risposta correttaperché Phpbloginfo ('version')?> Ti dà la versione corrente di wordpressmentre la domanda riguarda la versione append style.cssnon la versione wordpress.I think that it is not correct answer because gives you current wordpress version while question is about append style.css version not wordpress version.
- 0
- 2013-06-05
- Ravinder Kumar
Come aggiungere la versione di
style.css
in WordPress come di seguitopossofarein Joomla.so che
style.css
verrà caricato dinamicamente.perfavore aiutami a comefarlo.