for the currently displayed singular object. */ public static function render_head_markup(): void { // Adjust this if you only want standard posts: // if ( ! is_singular( 'post' ) ) { return; } if ( is_front_page() ) { $html = self::build_markup_for_front_page(); if ( $html === '' ) { return; } echo "\n" . $html . "\n"; return; } if ( ! is_singular() ) { return; } if ( ! is_singular() ) { return; } $post_id = get_queried_object_id(); if ( ! $post_id ) { return; } $post = get_post( $post_id ); if ( ! $post instanceof WP_Post ) { return; } if ( ! has_category( 'Kurzgeschichten', $post_id ) ) { return; } $html = self::build_markup_for_post( $post ); if ( $html === '' ) { return; } echo "\n" . $html . "\n"; } private static function make_description( string $text ): string { $target_length = 150; $parts = explode(' ', $text); $lengths = array_map('strlen', $parts); $total_length = 0; $i = 0; for ( ; $i < count($lengths); $i++ ) { if ( $total_length + $lengths[$i] > $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; } private static string $page_headline = "Da Ruady. Hansdampf in allen Gassen."; private static function build_markup_for_front_page(): string { $site_title = get_bloginfo( 'name' ); $site_url = site_url(); $site_url_p = parse_url($site_url); $site_host = $site_url_p['host']; $og_image_url = get_the_post_thumbnail_url(33, 'full'); $description = self::$page_headline; $og_description = self::$page_headline; ob_start(); ?> post_type !== 'post' ) { return ''; } $post_url = get_permalink( $post ); $post_title = get_the_title( $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']; $og_image_url = user_trailingslashit( trailingslashit( $post_url ) . 'og-image' ); $description = self::make_description(wp_strip_all_tags( $excerpt )); $og_description = self::$page_headline; // Example business logic: // - add a meta tag for every post // - add JSON-LD only if the post is in category "news" $is_news = has_category( 'news', $post ); ob_start(); ?> ID, $accent ); */ ////////////////////////////////// $excerpt = get_the_excerpt( $post ); $description = html_entity_decode(wp_strip_all_tags( $excerpt )); $fontFile = __DIR__ . '/fonts/EBGaramond-VariableFont_wght.ttf'; //$size = 28; $size = 36; $x = 60; $y = 120; $lineHeight = (int) ($size * 1.9); $maxWidth = 1080; $maxHeight = $height - 60; // wrap_text_ttf(string $text, int $maxWidth, string $fontFile, float $size) $lines = self::wrap_text_ttf($description, $maxWidth, $fontFile, $size); foreach ($lines as $line) { imagettftext($image, $size, 0, $x, $y, $fg, $fontFile, $line); $y += $lineHeight; if ($y > $maxHeight) break; } ////////////////////////////////// status_header( 200 ); header( 'Content-Type: image/png' ); header( 'Cache-Control: public, max-age=3600' ); imagepng( $image ); imagedestroy( $image ); exit; } private static function render_text_error( int $status, string $message ): void { status_header( $status ); header( 'Content-Type: text/plain; charset=utf-8' ); echo $message; exit; } private static function truncate( string $text, int $max_len ): string { if ( mb_strlen( $text ) <= $max_len ) { return $text; } return mb_substr( $text, 0, $max_len - 1 ) . '…'; } } Ruady_OG_Head::init();