'length', 'type' => 'number', 'label' => __('Length (words)', 'zadex'), 'default' => 55, 'min' => 0], ]; } public function render(array $settings, Context $ctx) { $post = $ctx->post(); if (!$post) { return ''; } $length = isset($settings['length']) && is_numeric($settings['length']) ? max(0, (int) $settings['length']) : 55; $excerpt = trim((string) ($post->post_excerpt ?? '')); if ($excerpt === '') { $content = (string) ($post->post_content ?? ''); if (function_exists('strip_shortcodes')) { $content = strip_shortcodes($content); } $excerpt = trim((string) preg_replace('/\s+/', ' ', wp_strip_all_tags($content))); } if ($length > 0) { $words = preg_split('/\s+/u', $excerpt, -1, PREG_SPLIT_NO_EMPTY) ?: []; if (count($words) > $length) { $excerpt = implode(' ', array_slice($words, 0, $length)) . '…'; } } return $excerpt; } }