Minimales WordPress CSS-Plugin-Beispiel

English Deutsch

Siehe auch: Minimales WordPress JS-Plugin-Beispiel Minimales WordPress Shortcode-Plugin-Beispiel

Dieses Plugin fügt eine statische CSS-Datei zu WordPress hinzu.

Erstellen Sie zuerst ein Verzeichnis für Ihr Plugin in wp-content/plugins/, z.B. wp-content/plugins/my-css-plugin

Speichern Sie den folgenden Code als functions.php im Plugin-Ordner, z.B. wp-content/plugins/my-css-plugin/functions.php

functions.php
<?php
/*
Plugin Name: My CSS plugin
*/

function my_plugin_enqueue_css(){
    wp_enqueue_style('my-plugin-stylesheet', plugins_url('/style.css', __FILE__), false, '1.0.0', 'all');
}
add_action('wp_enqueue_scripts', "my_plugin_enqueue_css");

Speichern Sie als Nächstes Ihre gewünschte CSS-Datei als style.css im Plugin-Ordner, z.B. wp-content/plugins/my-css-plugin/style.css. Beispiel für ein Stylesheet:

style.css
/* Dies ist nur ein Beispiel-CSS und hat keine spezifische Bedeutung! */
.my-plugin-class {
    font-weight: bold;
}

Aktivieren Sie nun Ihr Plugin im WordPress-Admin-Bereich.

Ihr CSS wird für jede WordPress-Seite geladen, bis Sie das Plugin deaktivieren.

Beachten Sie, dass bei Verwendung eines CSS-optimierenden Plugins wie Autoptimize Ihre CSS-Datei möglicherweise nicht als separat geladenes Stylesheet angezeigt wird, da sie in die einzelne Autoptimize-CSS kompiliert wird. Ihr Style wird dennoch geladen!


Check out similar posts by category: PHP, Wordpress