Um die voraussichtliche Lesezeit von Beiträgen auszugeben wird folgender Code in der Datei block-estimated-reading-time.php
im Verzeichnis blocks
benötigt:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?php // No direct access, please if ( ! defined( ‚ABSPATH‘ ) ) { exit; } // Estimated reading time $content = get_post_field( ‚post_content‘, $post->ID ); $word_count = str_word_count( strip_tags( $content ) ); $image_count = substr_count( $content, ‚<img‘ ); $reading_time = $word_count / 180; $image_time = ( $image_count * 10 ) / 60; $total_time = round( $reading_time + $image_time ); if ( $total_time == 1 ) { $reading_time = ‚eine Minute‘; } else { $reading_time = $total_time . ‚ Minuten‘; } if ( $total_time < 1 ) { $reading_time = ‚weniger als eine Minute‘; } echo ‚Voraussichtliche Lesezeit: ‘ . $reading_time; ?> |
Das Ergebnis kann zum Beispiel so aussehen:

Hinweis: Das Plugin Genesis Custom Blocks muss installiert und aktiviert sein.