From dea96e48fc61b3919e388e8e4e21046c0d07da45 Mon Sep 17 00:00:00 2001 From: David Madl Date: Sun, 1 Mar 2026 20:52:30 +0100 Subject: [PATCH] generate Open Graph meta tags for category = Kurzgeschichten --- ruady-og-head.php | 80 +++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/ruady-og-head.php b/ruady-og-head.php index 88259e9..f4c89b4 100644 --- a/ruady-og-head.php +++ b/ruady-og-head.php @@ -1,18 +1,20 @@ $target_length ) break; + $total_length += $lengths[$i]; + } + $desc = implode(' ', array_slice($parts, 0, $i)); + $ellipsis = substr($desc, -1, 1) == '.' ? '' : ' ...'; // full sentences with a '.' don't need ellipsis '...' + return $desc . $ellipsis; + } + /** * Build the head markup for one post. - * - * This is the function you will customize. */ private static function build_markup_for_post( WP_Post $post ): string { // Example 1: conditionally emit markup only for a specific post type. @@ -59,7 +78,13 @@ final class Per_Post_Head_HTML { $post_url = get_permalink( $post ); $post_title = get_the_title( $post ); - $excerpt = has_excerpt( $post ) ? get_the_excerpt( $post ) : ''; + $excerpt = get_the_excerpt( $post ); + $site_title = get_bloginfo( 'name' ); + $site_url = site_url(); + $site_url_p = parse_url($site_url); + $site_host = $site_url_p['host']; + + $description = self::make_description(wp_strip_all_tags( $excerpt )); // Example business logic: // - add a meta tag for every post @@ -68,36 +93,31 @@ final class Per_Post_Head_HTML { ob_start(); ?> + + + + + + + + + + + + + + + + + - - - - - - - -