9.8. Shortcodes umwandeln

WordPress wandelt alle Shortcodes des Editor-Inhalts automatisch in die entsprechenden Code um. Dazu nutzt es es den the_content Filter-Hook wie folgt:

<?php
add_filter( 'the_content', 'do_shortcodes' );
?>

Das bedeutet wiederum, dass die Funktion do_shortcodes() letztlich für die Umwandlung der eigentlichen Shortcodes hin zu HTML zuständig sein muss. WordPress definiert die Funktion wie folgt:

<?php
function do_shortcode( $content ) {
	...
}
?>

Es gilt:

  • $content (string)
    Ist der Inhalt dessen beinhaltete Shortcodes umgewandelt werden sollen.

Die Funktion gibt als String den Inhalt mitsamt umgewandelter Shortcodes zurück.

Beispiel 1

You’re not allowed to see this content. Please log in first.

Beispiel 2

You’re not allowed to see this content. Please log in first.

Beispiel 3

You’re not allowed to see this content. Please log in first.