Wie füge ich eine Version von style.css in WordPress hinzu
-
-
Hieristein Plugin https://wordpress.org/plugins/wp-css-version-history/,das automatischeine Versionsnummerim Stylesheet anfügt.Es wirdein neues Stylesheeterstellt,das zuletztgeladen wird.Siemüssen den Cachenicht leeren,um Änderungen zu sehen.Verwendet denim CSS-Editor undin der Benutzerdateigesperrten Wordpressfür die Teamzusammenarbeit.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 Antworten
- Stimmen
-
- 2013-03-14
Die Versionsnummeristein Parameter von
wp_enqueue_style()
.Gemäß Codex sind hier alle Parameter aufgeführt,die
wp_enqueue_style
akzeptiert.wp_enqueue_style( $handle, $src, $deps, $ver, $media );
Umbeispielsweiseein Stylesheetmit einer Versionsnummer zu laden,gehen Sie wiefolgt vor:
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');
-
Wennich dasmache,wird auch die alte style.cssgeladen.Wieentferneiches?when i do this the old style.css is also loading. How to remove it?
- 0
- 2013-03-14
- Toretto
-
@ VinodDalvi wasmeinst dumit handle.Ich weißnicht,ichbin neuin WordPress,bitte ich.@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 Entweder wird Ihr Themain der Datei header.phpfest codiert,oder Ihr Thema wird auchmit einem anderen Handle (demersten Parameter)in die Warteschlangegestellt.Die Lösung hängt auch davon ab,ob Sie die Dateifunctions.php Ihres Themas direktbearbeiten oder ob Sieein untergeordnetes Themaerstellt haben.@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 wirdin meiner Antwort angezeigt und auchin dem Linkbeschrieben,denich zur Codex-Seitefür `wp_enqueue_style`bereitgestellt habe. Bittemachen Sie Ihre Hausaufgaben.@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 Wie kannich den alten Handlernamen kennen?@helgatheviking how can i know the old handler name.
- 0
- 2013-03-14
- Toretto
-
@Toretto Wenn Ihr Thema "wp_enqueue_style ()" verwendet,um dasbetreffende Stylesheet zu laden,ist sein Handle der *erste * Parameter.Wenn Ihr Thema das Stylesheetin header.phpfest codiert,hates kein 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,ich habees,ich habemeine Standard-Design-Funktionersetzt undesbeginnt zufunktionieren. Vielen Dank @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
Anstatt die Versionfest zu verdrahten,istesin einigen Fällenmöglicherweisebesser,Ihr Stylesheet dynamisch zu versionieren. Wenn Siees ändern,wird der Browser-Cache automatisch sofortgeändert und aktualisiert,ohne dass Sie Ihrefunctions.phpimmer wiederbearbeitenmüssen.
Sie können dazufilemtime () verwenden.Hiererfahren Sie,wie Sie diesin einem untergeordneten Stiltun,der auf den übergeordneten Stil
verweistwp_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' ) );
-
Mit der Zeitbevorzugeich Theme-Versionen,aberesisteine gute Idee,hierfilemtime () zu verwenden,wennman keine konsistente Versionierungspraxisfür Themes hat.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
Wenn Sieein Theme-Entwickler sind,möchten Siemöglicherweise das Neuladen Ihrer Assetserzwingen,wenn Sieeine neue Version veröffentlichen.
Die Versionierungeines Themaserfolgt alsoin
style.css
/* Theme Name: Your Theme Name Version: 1.0.2 */
Obenin Ihrer
functions.php
:$theme = wp_get_theme(); define('THEME_VERSION', $theme->Version); //gets version written in your style.css
Wenn Sie später CSS oder JSin die Warteschlange stellen,verwenden Sie
THEME_VERSION
als viertes 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');
Wird auf der Seite ausgegeben:
.../your-theme-name/css/main.css?ver=1.0.2
Istpraktisch,wenn Siemehr Assetsbenötigen und diesenichtmanuell ändernmöchten.
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
Sie können dies aufeine derfolgenden Artenerreichen:
1) Fügen Sie dasfolgende Tagin die Datei header.php des Themasein.
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>'?v=1.2" type="text/css" media="all" />
2) Fügen Sie denfolgenden Codein die Dateifunctions.php des Themasein.
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');
Weitere Informationenfinden Sie unter dieser Seite.
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.
-
Wennich dasmache,wird auch die alte style.cssgeladen.Wieentferneiches?when i do this the old style.css is also loading. How to remove it?
- 0
- 2013-03-14
- Toretto
-
Wasist der Griff von old style.css?What is the handle of old style.css?
- 0
- 2013-03-14
- Vinod Dalvi
-
Wenn Sie das Handlenichtfinden können,kopieren Sieeinfach diegesamte style.css-URL hier undfügen Sie sieein. Ich werde sie von dorterhalten ...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
-
Oder können Siemir sagen,wie Ihr Themenname oder Themenordnername lautet?Or can you tell me whats your theme name or theme's folder name?
- 0
- 2013-03-14
- Vinod Dalvi
-
Ok,ich habees,ich habemeine Standard-Design-Funktionersetzt undesfunktioniert. Danke. + 1 vonmir.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
-
Herzlich willkommen .... :)Welcome .... :)
- 1
- 2013-03-14
- Vinod Dalvi
-
- 2015-06-08
Derbeste Weg,um CSSin Ihr WordPress-Theme zu laden,ist derfolgende Codein Ihrer Dateifunctions.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');
Diesist der richtige Weg,um die Stilein Ihr Thema zu laden,und auch derbestefür Staging-/Testzwecke,dajede Aktualisierung die aktualisierte Version des Stils liefert.
Wenn Sie das Laden auf dieerste Weise vermeidenmöchten,können Sie diese kurzgeschlossene Version verwenden und diefolgende Zeilein Ihre Datei header.phpeinfügen,um dasgleiche Ergebnis zuerhalten:
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); echo '?ver=' . filemtime( get_stylesheet_directory() . '/style.css'); ?>" type="text/css" media="screen, projection" />
Prost
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
Versuchen Sie Folgendes:
Fügen Sie dies zufunctions.php
hinzufunction 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(); }
Fügen Sie dies der Kopf- oder Fußzeile hinzu -> 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
Im Gegensatz zu denbisher vorgestellten Methodenistesmeiner Meinungnachbesser,die Versionsnummer zu verwenden,die obenin Ihrer style.css-Datei angezeigt wird:
// style.css /** Theme Name: My theme ... Version: 1.2.3 ... **/
Um die Version des Themasin Ihrem CSS zu verwenden,fügen Sie Ihrem Skriptfunctions.php (odereinem gleichwertigen Skript) Folgendes hinzu:
<?php wp_enqueue_style( 'my-theme', get_stylesheet_directory_uri() . '/style.css', [], wp_get_theme()->get('Version') );
Diesbedeutet,dass Sienach dem Bearbeiten Ihrer style.css-Datei lediglich die Versionsnummer obenin derselben Datei ändernmüssen,um die Änderungenim Frontend anzuzeigen.
Wenn Sie den Kopfabschnitt des HTML-Codes des Themas untersuchen,sehen Sie Folgendes:
<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
Eine andere Lösung,wenn Sieesnochnicht herausfinden können,besteht darin,den Dateinamen der Datei style.css Ihres untergeordneten Themasin beispielsweise style2.css zu ändern undihn dann wiegezeigtin der Dateifunctions.php Ihres untergeordneten Themas zu ändernunten:
wp_enqueue_style( 'style', get_stylesheet_directory_uri() .'/style2.css' );
Dadurchfordert Wordpresseine neue CSS-Dateifür Ihre Website an und stellt siebereit.
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
Auf diese Weise können Sie die Versionsnummerganzeinfach abrufen,indem Sie die -Funktion
bloginfo($show)
zweimal.Erstensfür das Stylesheet und zweitensfür die Versionsnummer.<link rel="stylesheet" id="style-css" href="<?php bloginfo('stylesheet_url'); ?>?ver=<?php bloginfo('version'); ?>" type="text/css" media="all" />
Dasist alles,was dazugehört.Hoffe das hilft oderistnützlich.Sie können alle verfügbaren Parameter durchgehen und sehen,was Siemit der Funktion
bloginfo()
ausgeben können.Ignorieremeinen Kommentar,da @Ravs aufmeinen Fehlerbezüglich des Parameters 'Versionen'für die Funktionbloginfo () hingewiesen hat.Es wirdtatsächlich die Wordpress-Versionsnummergedruckt.
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.
-
Ich denke,dassesnicht die richtige Antwortist,weil Phpbloginfo ('version')?> Ihnen die aktuelle WordPress-Versiongibt,während die Frage über das Anhängen der style.css-Version undnicht der WordPress-Version lautet.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
Wiefügeicheine Version von
style.css
in WordPress hinzu,wie untenin Joomla.Ich weiß,dass die Datei
style.css
dynamischgeladen wird.Bitte helfen Siemir dabei.