add_action('wp_head', function () { if (!is_single()) return; global $post; $cats = get_the_category($post->ID); $words = count(preg_split('/\s+/u', trim(wp_strip_all_tags($post->post_content)))); $data = array( 'article_id' => $post->ID, 'article_category' => $cats ? $cats[0]->name : '', 'article_author' => get_the_author_meta('display_name', $post->post_author), 'publish_date' => get_the_date('Y-m-d', $post), 'word_count' => $words, ); echo ''; }, 1);