Minimales WordPress Shortcode-Plugin-Beispiel

English Deutsch

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

Dieses Plugin erstellt einen einfachen (statischen - keine Parameter) Shortcode in WordPress

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

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

my_shortcode_plugin.php
<?php
/*
Plugin Name: My shortcode plugin
*/

function my_shortcode( $atts , $content = null ) {
    return '<h2>Shortcode funktioniert</h2>';
}

add_shortcode( 'my-shortcode', 'my_shortcode' );

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

Sie können nun einen Beitrag oder eine Seite erstellen, der/die diesen Code enthält:

shortcode_usage.txt
[my-shortcode][/my-shortcode]

was wie folgt gerendert wird:

shortcode_output.txt
Shortcode funktioniert
---------------

Check out similar posts by category: PHP, Wordpress