Last active
August 20, 2021 10:29
-
-
Save nextab/1c764bf5f501e339c5d7340981bc5402 to your computer and use it in GitHub Desktop.
Wir liefern einige einfache Vorlagen für Shortcodes in WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Einfaches Beispiel, für einen simplen Shortcode, der das Jahr (4-stellig) ausgibt. | |
Anwendung: | |
[jahr] | |
*/ | |
function jahr_function( $atts ) { | |
return date('Y'); | |
} | |
add_shortcode( 'jahr', 'jahr_function' ); | |
/* Etwas komplexerer Shortcode [highlight], der ein "div" um den $content (steht zwischen dem öffnenden und dem schließenden Shortcode-Tag) packt und diesem eine Klasse zuweist, die übergeben werden kann und mit dem Standardwert "highlight" versehen ist. | |
Anwendung: | |
[highlight]Dies ist mein hervorgehobener Text[/highlight] | |
*/ | |
function highlight_shortcode( $atts, $content = null ) { | |
$a = shortcode_atts( [ | |
'class' => 'highlight', | |
], $atts ); | |
return '<div class="' . esc_attr($a["class"]) . '">' . $content . '</div>'; | |
} | |
add_shortcode( 'highlight', 'highlight_shortcode' ); | |
/* Tiefere Infos zu Shortcodes: | |
- https://www.sitepoint.com/custom-shortcodes-for-wordpress/ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment